We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

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 ...

4 Replies

TE Testname April 9, 2016 04:40 AM UTC

no, i managed it with a for loop and ""worksheet.ImportData(_excelObjekt, ..., false);//  "excelObjekt" contains a List<string[]> to fill an excel, but he clears out the first row of my excel, but there was some writing in it before, what to do?


AV Abirami Varadharajan Syncfusion Team April 11, 2016 01:03 PM UTC

Hi Testname,

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.


TE Testname April 11, 2016 01:12 PM UTC

How to use your example with a given Memorystream( with the existing excel document) ?


AV Abirami Varadharajan Syncfusion Team April 12, 2016 09:12 AM UTC

Hi Testname,

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.

Loader.
Up arrow icon