Hi everybody!
I'm trying to solve a problem on excel.
So it's the following. I need to create a timer where it adds 3 to the variable final each 30 seconds . . This is already done.
Now it needs to create an excel sheet and write the value of final on cell [5,2].
Code is:
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
xla.Visible = true;
ws.Cells[1, 1] = "Primeiro";
ws.Cells[1, 2] = "Último";
ws.Cells[3, 1] = txtprimeiro.Text;
ws.Cells[3, 2] = txtultimo.Text;
ws.Cells[5, 1] = "Tempo:";
ws.Cells[5,2 ] = final;
Done too!
Now it needs to add the value of final and save the sheet. Next time users push start button cell [5,2] should show the value of the cell + new final value.
To save, I use the following:
string activDir = @"C:";
string newPath = System.IO.Path.Combine(activDir, "exemplo");
System.IO.Directory.CreateDirectory(newPath);
ws.SaveAs(@"C:\exemplo\teste");
To find the value of cell [5,2] :
Range a1 = ws.Cells[5, 2];
double rawValue;
if(a1.Value == null)
{
rawValue = 0;
}
else
{
rawValue = a1.Value;
}
ws.Cells[5, 2] = final + rawValue;
This isn't working. What's wrong with this?