C# AddIn Excel : export xls file in text file with separator -


it's first addin excel , i've problem export excel's file in text file separator ("|"). export excel's file in same path, extension ".txt" , separate excel's columns specific character ("|").

i've created button on ribbon :

private void exportsave_click(object sender, ribboncontroleventargs e)     {         int lastcolumns;                    lastcolumns = usedrange.columns.count;         int endcol = lastcolumns;          microsoft.office.interop.excel.worksheet xlsheet = globals.vattools.application.activesheet;         microsoft.office.interop.excel.range usedrange = xlsheet.usedrange;          // save file in .txt in same path         string path = system.io.path.getdirectoryname(process.getcurrentprocess().mainmodule.filename);         xlsheet.saveas(path, microsoft.office.interop.excel.xlfileformat.xltextwindows);     } 

i'm not sure of format "xltextwindows".

i identify columns don't know how add specific character between columns before exporting .txt

thanks !

try following code:

public static void exporttopipe(ribboncontroleventargs e) {     string exportname = @"d:\pipe.txt";     excel.window window = e.control.context;     excel.worksheet sheet = ((excel.worksheet)window.application.activesheet);     excel.range last = sheet.cells.specialcells(excel.xlcelltype.xlcelltypelastcell, type.missing);       int lastusedrow = last.row;     int lastusedcolumn = last.column;      string output = "";      (int = 1; <= lastusedrow; i++)     {         (int j = 1; j <= lastusedcolumn; j++)         {             if (sheet.cells[i, j].value != null)             {                 output += sheet.cells[i, j].value.tostring();                                     }             output += "|";         }         output += environment.newline;      }       filestream fs = new filestream(exportname, filemode.create, fileaccess.write);      streamwriter writer = new streamwriter(fs);      writer.write(output);      writer.close(); } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -