Note that there are some explanatory texts on larger screens.

plurals
  1. POExport DataTable to Excel with Open Xml SDK in c#
    primarykey
    data
    text
    <p>Sorry for my english please. I'm new in open xml sdk. My program have ability to export some data and DataTable to Excel file (template) In the template I insert the data to some placeholders. It's works very good, but I need to insert a DataTable too... My sample code:</p> <pre><code>using (Stream OutStream = new MemoryStream()) { // read teamplate using (var fileStream = File.OpenRead(templatePath)) fileStream.CopyTo(OutStream); // exporting Exporting(OutStream); // to start OutStream.Seek(0L, SeekOrigin.Begin); // out using (var resultFile = File.Create(resultPath)) OutStream.CopyTo(resultFile); </code></pre> <p>Next method to exporting</p> <pre><code>private void Exporting(Stream template) { using (var workbook = SpreadsheetDocument.Open(template, true, new OpenSettings { AutoSave = true })) { // Replace shared strings SharedStringTablePart sharedStringsPart = workbook.WorkbookPart.SharedStringTablePart; IEnumerable&lt;Text&gt; sharedStringTextElements = sharedStringsPart.SharedStringTable.Descendants&lt;Text&gt;(); DoReplace(sharedStringTextElements); // Replace inline strings IEnumerable&lt;WorksheetPart&gt; worksheetParts = workbook.GetPartsOfType&lt;WorksheetPart&gt;(); foreach (var worksheet in worksheetParts) { DoReplace(worksheet.Worksheet.Descendants&lt;Text&gt;()); } int z = 40; foreach (System.Data.DataRow row in ExcelWorkXLSX.ToOut.Rows) { for (int i = 0; i &lt; row.ItemArray.Count(); i++) { ExcelWorkXLSX.InsertText(workbook, row.ItemArray.ElementAt(i).ToString(), getColumnName(i), Convert.ToUInt32(z)); } z++; } } } } </code></pre> <p>But this fragment to output DataTable slooooooooooooooooooooooowwwwwww...</p> <p>How can I export DataTable to Excel fast and truly?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload