hi,
I am not opening the Excel file from a txt file.
I 'am reading a txt file and then create at runtime an Excel.
Here the code :
private static void ReadFile(string path, IWorksheet sheet)
{
using (StreamReader sr = new StreamReader(path))
{
char[] delimiter = { '\t' };
string[] columnheaders = sr.ReadLine()?.Split(delimiter);
int j = 1;
// headers
foreach (string colheader in columnheaders)
{
sheet.Range[1, j].Text = colheader;
sheet.Range[1, j].HorizontalAlignment = ExcelHAlign.HAlignCenter;
sheet.Range[1, j].AutofitColumns();
j++;
}
int i = 3;
// rows
while (sr.Peek() > 0)
{
j = 1;
var row = sr.ReadLine().Split(delimiter);
foreach (var rowCell in row)
{
sheet.Range[i, j].Text = rowCell;
sheet.Range[i, j].HorizontalAlignment = ExcelHAlign.HAlignLeft;
sheet.Range[i, j].AutofitColumns();
j++;
}
i++;
}
sheet.Range["A1:Z1"].AutofitColumns();
}
}
I tried to force the view with :
"sheet.Range["A1:Z1"].AutofitColumns();",
but it didnt work.
Any suggestions?
thank you
Davide