c# - Exporting to excel with carriage returns -
i trying export excel datagrid
. datagrid
has column put comments in. in column comments put on separate lines. when exports excel exports in multiple rows.
here how looks in datagrid
:
here how looks when export excel:
here code using it:
public static void createexcelfromclipboard(string worksheetname, string fullfilepath, bool toopen) { //excel application class _application app = new microsoft.office.interop.excel.application(); //get process id int excelprocessid = getapplicationprocessid(app); try { //add workbook workbook theworkbook = app.workbooks.add(xlwbatemplate.xlwbatworksheet); //add worksheet var theworksheet = (worksheet)theworkbook.worksheets.add(type.missing, type.missing, type.missing, type.missing); theworksheet.name = worksheetname; app.sheetsinnewworkbook = 1; app.displayalerts = false; theworksheet.activate(); //paste worksheet clpboard theworksheet.paste(type.missing, type.missing); //apply borders applyborder(theworksheet.usedrange); //auto fit columns range xlrange = theworksheet.usedrange; // put hardcodes in constant class xlrange.font.name = "arial"; xlrange.font.size = 9; var firstrowrange = (range)xlrange.rows[1, missing.value]; firstrowrange.entirerow.font.bold = true; firstrowrange.entirerow.horizontalalignment = xlhalign.xlhaligncenter; //set wrap test false xlrange.wraptext = true; xlrange.columns.autofit(); theworksheet.activate(); //save file theworkbook.saveas(fullfilepath, xlfileformat.xlopenxmlworkbook, type.missing, type.missing, type.missing, type.missing, xlsaveasaccessmode.xlnochange, type.missing, type.missing, type.missing, type.missing, type.missing); if (!toopen) { //clean app.quit(); marshal.releasecomobject(app); } } catch { forceexcelclose(excelprocessid); throw; } { app.visible = toopen; } }
Comments
Post a Comment