I have a function to export datagridview to excel using CloedXML. Everything works ok, BUT:
I add columns from datagridview to datatable using
foreach (DataGridViewColumn column in dgvLoadAll.Columns)
{
dt.Columns.Add(column.Name);
}
This uses column.Name which is Design (Name) in my dgv. I want to add column.HeaderText. When I use
dt.Columns.Add(column.HeaderText, typeof(string));
it adds column headers sucessfully, but export does not work ok. It only exports columns where there are no special characters or even blank char. ("Name" column is exported, but "IUPAC Name", or "Čas" is not, ...). Renaming is not an option.
Here is the part of export function responsible for writing cells. Just reminder: It works 100% OK when I use column.Name.
foreach (int rowindex in rowsselected)
{
foreach (int columnindex in columnsList)
{
worksheet.Cell(k+2, j+1).Value = dt.Rows[rowindex] [columnindex].ToString();
j++;
}
j = 0;
k++;
}