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

ImportData

Hello,

I am trying to import data from my database to a worksheet. I'm using EF6 to bring the data.

list = new SortableBindingList<Document>();
Context.Documents.Where(p =>
                (p.CreatedOn >= startdt && p.CreatedOn < enddt) &&
                (p.TemplatePath.ToLower().Contains(DocsFilter) ||
                 p.Name.ToLower().Contains(DocsFilter) ||
                 p.Comments.ToLower().Contains(DocsFilter))
              ).ToList().ForEach(p => list.Add(p)); 

ExcelEngine excelEngine = new ExcelEngine();

            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook = application.Workbooks.Create(1);
            IWorksheet worksheet = workbook.Worksheets[0];
           
         
            IList<Document> docs = list
         
            worksheet.ImportData(docs, 2, 1, false);

            workbook.SaveAs("E:\\temp\\Output\\Spre.xlsx");

I don't know why but I do not get the data in Excel. 

Thank you in advance!
Costin

6 Replies

AV Abirami Varadharajan Syncfusion Team January 20, 2016 12:00 PM UTC

Hi Constantin,

We are unable to reproduce the reported issue while importing a data from datatable. We have shared a sample illustrating how to import a data from datatable which can be downloaded from following link.
Sample link http://www.syncfusion.com/downloads/support/directtrac/general/ze/ImportData-386617835.zip

If you are still able to reproduce the issue then please share us the issue reproducing sample which will be helpful for us to give a prompt solution at the earliest.

Regards,
Abirami.


AV Abirami Varadharajan Syncfusion Team January 20, 2016 12:39 PM UTC

Hi Constantin


You can also refer our below UG documentation link to know more about importing data in XlsIO.


UG Documentation link: http://help.syncfusion.com/file-formats/xlsio/working-with-data#importing-data-to-worksheets


Regards,

Abirami.



CC Constantin Constantinescu January 20, 2016 10:59 PM UTC

Hi Abirami,

Thank you for your reply. I changed a little the way of implementing it. I was abletu adapt my code and use ImportDataTable.

Regards, 
Constantin


AV Abirami Varadharajan Syncfusion Team January 21, 2016 04:35 AM UTC

Hi Constantin,


We are glad to know that the issue has been resolved. Please let us know if you need any further assistance on this.

Regards,
Abirami.



CC Constantin Constantinescu January 21, 2016 10:04 AM UTC

Hi,

I would also like to know how cand I show a SaveAs Dialog for my Excel Workbook.

 ExcelEngine excelEngine = new ExcelEngine();
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook = application.Workbooks.Create(1);
            IWorksheet worksheet = workbook.Worksheets[0];
            worksheet.ImportDataTable(dt, true, 1, 1, true);
workbook.SaveAs("E:\\temp\\Output\\Spreadsheet.xlsx");

I want to let the user choose about name and where to save the Excel Document.

Regards,
Constantin


AV Abirami Varadharajan Syncfusion Team January 22, 2016 07:04 AM UTC

Hi Constantin,

Yes, you can save the workbook in any location using SaveAsDialog. We have shared a sample illustrating this behaviour which can be downloaded from following link.


Sample link:
http://www.syncfusion.com/downloads/support/directtrac/general/ze/SaveFile-381635603.zip

Please let us know if you have any concerns on this.

Regards,

Abirami.


Loader.
Live Chat Icon For mobile
Up arrow icon