C# of excel
Jeg vil læse en excel fil. Jeg bruger// create the workbook object by opening the excel file.
string path = @"c:\testC.xls";
Excel.Workbook workBook = app.Workbooks.Open(path,
0,
true,
5,
"",
"",
true,
Excel.XlPlatform.xlWindows,
"\t",
false,
false,
0,
true,
1,
0);
// get the active worksheet using sheet name or active sheet
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 0;
// This row,column index should be changed as per your need.
// i.e. which cell in the excel you are interesting to read.
object rowIndex = 2;
object colIndex1 = 1;
object colIndex2 = 2;
object colIndex3 = 3;
try
{
MessageBox.Show("openFile2" + ((((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2) != null).ToString());
while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null)
{
MessageBox.Show("openFile3");
string fullName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2.ToString();
string userID = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2.ToString();
string komName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex3]).Value2.ToString();
MessageBox.Show("FullName=" + fullName + "USER=" + userID + "KOM=" + komName + "index=" + index);
index++;
rowIndex = 2 + index;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
app.Quit();
}
Det går fint når jeg selv skriver filen C:\testC.xls. Men når jeg
åbner en xls fil fra internetet der er som om det ikke kan læse
tegn som er skrevet der. Vi åbner en excel fil fra internetet ved
at sige gem som regneark. Hvad er galt?