excel - delete Style in Execl Using C# -


i created excel file using code:

sheets worksheets = wb.sheets; worksheet worksheet = (worksheet)worksheets[4]; int rows = dt.rows.count; int columns = dt.columns.count; var data = new object[rows + 1, columns];  (var column = 0; column < columns; column++) {   data[0, column] = dt.columns[column].columnname; }  (var row = 0; row < rows; row++) {   (var column = 0; column < columns; column++)   {     data[row + 1, column] = dt.rows[row][column];   } }  range beginwrite = (range)worksheet.cells[1, 1]; range endwrite = (range)worksheet.cells[rows + 1, columns]; range sheetdata = worksheet.range[beginwrite, endwrite]; sheetdata.value2 = data; worksheet.select(); sheetdata.worksheet.listobjects.add(xllistobjectsourcetype.xlsrcrange,   sheetdata,   type.missing,   xlyesnoguess.xlno,   type.missing);  sheetdata.select(); excel.activewindow.displaygridlines = false; excel.application.range["2:2"].select(); excel.application.range["$a$3"].select(); 

the problem here set default format style excel file
i don't know how clear format style in excel sheet

if trying delete styles, work:

using excelx = microsoft.office.interop.excel;  excelx.workbook wb = excel.activeworkbook;  foreach (excelx.style st in wb.styles)     st.delete(); 

then again, may want clear out custom styles (not ones come standard), in case small modification it:

foreach (excelx.style st in wb.styles) {     if (!st.builtin)         st.delete(); } 

styles stored @ workbook level, @ point need declare workbook. there, styles collection of workbook object has need.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -