protected string Name;
protected string Description;
protected void Page_Load(object sender, EventArgs e)
{
ExcelFile ef = new ExcelFile();
string fileName = @"C:\locationOfSpreadsheet.xlsx";
ef.LoadXlsx(fileName, XlsxOptions.PreserveMakeCopy);
StringBuilder sb = new StringBuilder();
foreach (ExcelWorksheet sheet in ef.Worksheets)
{
sb.AppendLine();
sb.AppendFormat("------{0}--------", sheet.Name);
foreach (ExcelRow row in sheet.Rows)
{
sb.AppendLine();
Description = row.Cells[0].Value;
foreach (ExcelCell cell in row.AllocatedCells)
{
if (cell.Value != null)
{
Label x = new Label();
x.Text = cell.Value.ToString();
uploadExcel.Controls.Add(x);
sb.AppendFormat("{0}({1})", cell.Value, cell.Value.GetType().Name);
sb.Append("\t");
}
}
}
}
Console.WriteLine(sb.ToString());
}
Inside the 2nd for loop I am using Description = row.Cells[0].Value; but its throwing an error about can't convert an object to a string, but I don't think i'm on the right path anyway so....
This reads in the excel doc fine as I can display it on screen but I want to transfer the data over to the variables declared at the top name and description, which are the second and third column in the doc.
Please help

New Topic/Question
Reply



MultiQuote




|