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.
Unfortunately, activation email could not send to your email. Please try again.

Leave out the first row for headines and fill the rest of the excel with a given List<string[]>?

Thread ID:

Created:

Updated:

Platform:

Replies:

123666 Apr 8,2016 04:56 AM Apr 12,2016 05:12 AM ASP.NET MVC 4
loading
Tags: XlsIO
Testname
Asked On April 8, 2016 04:56 AM



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

Testname
Replied On April 9, 2016 12:40 AM

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?

Abirami Varadharajan [Syncfusion]
Replied On April 11, 2016 09:03 AM

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.

Testname
Replied On April 11, 2016 09:12 AM

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

Abirami Varadharajan [Syncfusion]
Replied On April 12, 2016 05:12 AM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;