Answer the question
In order to leave comments, you need to log in
How to transfer DataGridView as table to excel c# file?
In general, it is necessary to generate a report for printing and save it immediately into an .xlsx file. To do this, I use the SpreadsheetLight library (I tried ClosedXML, but it did not grow together with it).
I tried to transfer in a cycle (each cell separately to a cell in excel + apply styles), but I crash with an index error (moreover, if there are numbers in the cell, everything is transferred ok, if the text in the cell is a row index error). MB is there any normal transfer method?
Answer the question
In order to leave comments, you need to log in
I use the NPOI library, it works with both xls and xlsx.
Unfortunately, there are no special tools for import-export to the grid (such as one line of code) in this library. But the algorithm is quite easy to implement, given a number of nuances, for example, the need to create a cell before assigning knowledge to it.
Here is an example of both import and export from the grid:
www.codeproject.com/Tips/813187/Csharp-Read-and-wr...
and there is also an option with another approach to working with Excel - through ADO
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question