- Home
- Forum
- ASP.NET MVC
- Leave out the first row for headines and fill the rest of the excel with a given List<string[]>?
Leave out the first row for headines and fill the rest of the excel with a given List<string[]>?
I have:
//todo: convertiere objekte in die Tabelle
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Import the data to worksheet.
worksheet.ImportData(_excelObjekt, 2, 1, false);// "excelObjekt" contains a List<string[]>
workbook.SaveAs(filelocation);
workbook.Close();
excelEngine.Dispose();
But this will return a new empty excel file ...
Thank you for contacting Syncfusion support.
We are able to reproduce the issue. As per XlsIO behaviour, ImportData method imports only the list objects in the specified row and column. We request you to use ImportArray method to import list of string array. Kindly refer the below code example to achieve your requirement and let us know if it helps.
Code Example:
|
ExcelEngine excelEngine = new ExcelEngine(); IApplication application = excelEngine.Excel; IWorkbook workbook = application.Workbooks.Create(2); IWorksheet worksheet = workbook.Worksheets[0]; List<string[]> quarters = new List<string[]>(); string[] quarter1={"Jan","Feb","Mar"}; string[] quarter2 = { "Apr","May", "Jun" }; string[] quarter3 = { "jul", "aug","sep" }; string[] quarter4 = { "oct", "nov", "dec" }; quarters.Add(quarter1); quarters.Add(quarter2); quarters.Add(quarter3); quarters.Add(quarter4); for (int i = 0; i < quarters.Count; i++) { worksheet.ImportArray(quarters[i], 2 + i, 1, false); } workbook.Version = ExcelVersion.Excel2013; workbook.SaveAs(“Output.xlsx”); workbook.Close(); excelEngine.Dispose(); |
Regards,
Abirami.
As per your requirement, we have prepared a sample with an existing excel document as a memory stream. Kindly refer the sample which can be downloaded from the following link.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/ImportStringData-614611913.zip
Please let us know if you have any concerns.
Regards,
Abirami.
- 4 Replies
- 2 Participants
-
TE Testname
- Apr 8, 2016 08:56 AM UTC
- Apr 12, 2016 09:12 AM UTC