so I decided it would be ok to learn a bit of C# and now I am about to go ona rampage. Why does it seem that VB is so much easier to use???
anyway here is the issue
Through my app I create an excel sheet and save it as such:
xlBook.SaveAs("C:\\Program Files\\Hawkeye Customs\\Ship Margin Reports\\Reports\\" + strFileName + ".xls",
XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, false, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
so far so good. Now I open it up again to do some formatting using this code:
Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Open(strFileName, 0, false, 5, "", "", false,
XlPlatform.xlWindows, "",true, false, 0, true, false, false);
Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Worksheet)xlBook.Worksheets.get_Item("Sheet1");
I am guessing all is good so far. At this point I would like to convert some cell from text to numeric values. in VB it was simple:
xlSheet.Cells(2, 5) = CDbl(xlSheet.Cells(2, 5).value)
It eludes me how to do this very same thing in C#. Any help would be great.
Also I am not sure what is going on with this as well, but when I do this:
for (int intR = 0; intR <= iRows - 1; intR++)
{
xlRange = xlSheet.get_Range("G" + (intR + 3).ToString(), "G" + (intR + 3).ToString());
Debug.WriteLine(xlRange.Cells.Value2);
}
I get 2 as a result for every row, yet the value is the particular cell in the excel sheet that is created is totally different.
Any help will be greatly appreciated
Thanx
anyway here is the issue
Through my app I create an excel sheet and save it as such:
xlBook.SaveAs("C:\\Program Files\\Hawkeye Customs\\Ship Margin Reports\\Reports\\" + strFileName + ".xls",
XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, false, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
so far so good. Now I open it up again to do some formatting using this code:
Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Open(strFileName, 0, false, 5, "", "", false,
XlPlatform.xlWindows, "",true, false, 0, true, false, false);
Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Worksheet)xlBook.Worksheets.get_Item("Sheet1");
I am guessing all is good so far. At this point I would like to convert some cell from text to numeric values. in VB it was simple:
xlSheet.Cells(2, 5) = CDbl(xlSheet.Cells(2, 5).value)
It eludes me how to do this very same thing in C#. Any help would be great.
Also I am not sure what is going on with this as well, but when I do this:
for (int intR = 0; intR <= iRows - 1; intR++)
{
xlRange = xlSheet.get_Range("G" + (intR + 3).ToString(), "G" + (intR + 3).ToString());
Debug.WriteLine(xlRange.Cells.Value2);
}
I get 2 as a result for every row, yet the value is the particular cell in the excel sheet that is created is totally different.
Any help will be greatly appreciated
Thanx