I have to load an existed xlsx with predefiend cell styles, and paste data from csv to it.
I know I can
package.Workbook.Worksheets[0].Cells[1,1].Value ="somevalue"
without overwrite the original styles.
but to deal with a csv with so many data, I shouldn't write the data 1 by 1, right?
So I tried:
package.Workbook.Worksheets[0].Cells[1,1].LoadFromText("csvTableStr" , new ExcelTextFormat() , TableStyles.None , false);
and find that the styles(background color, data type, cell border and so on) are all reset to plain.
I am wondering if there is an option to load the data with respect to the existed styles, something like "TableStyles.Current". Or maybe a way to workaround?
The 3rd argument of LoadFromText()
is a Nullable. So, you may pass null to this argument if you don't want to apply a predefined style to your table. Try this:
package.Workbook.Worksheets[0].Cells[1,1].LoadFromText("csvTableStr" , new ExcelTextFormat() , null , false);