Код: Выделить всё
public void WriteDataToXlsx(List dataRows)
{
try
{
// Create a new Excel workbook
using (var workbook = new XLWorkbook())
{
// Add a new worksheet to the workbook
var worksheet = workbook.Worksheets.Add("Sheet1");
// Populate the worksheet with data
for (int rowIdx = 0; rowIdx < dataRows.Count; rowIdx++)
{
List rowData = dataRows[rowIdx];
for (int colIdx = 0; colIdx < rowData.Count; colIdx++)
{
// Get the cell using 1-based indexing
var cell = worksheet.Cell(rowIdx + 1, colIdx + 1);
// Set the cell value
cell.Value = rowData[colIdx];
cell.Style.NumberFormat.Format = "@"; // The '@' symbol denotes text format in Excel
}
}
worksheet.ColumnsUsed().AdjustToContents();
// Save the Excel workbook to a file
workbook.SaveAs(filePath);
}
MessageBox.Show($"Data successfully exported to location: '{filePath}'");
}
catch (Exception e)
{
Console.WriteLine($"An error occurred while writing to XLSX file: {e.Message}");
Console.WriteLine(e.StackTrace); // Print stack trace for debugging
}
}
{ "Method 'ErrorValue' in type 'AstFactory' from assembly 'ClosedXML, Version=0.105.0.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b' does not have реализация. ":" astfactory "} < /p>
< /blockquote>
Кто -нибудь знает, как это исправить? Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/797 ... el-c-sharp
Мобильная версия