C# 使用C语言在Excel中将单元格内容转换为字符串数据类型#
在下面的代码中,我得到了这种异常 Data_Consistency.exe中发生类型为“System.Runtime.InteropServices.COMException”的未处理异常 其他信息:来自HRESULT的异常:0x800A03ECC# 使用C语言在Excel中将单元格内容转换为字符串数据类型#,c#,C#,在下面的代码中,我得到了这种异常 Data_Consistency.exe中发生类型为“System.Runtime.InteropServices.COMException”的未处理异常 其他信息:来自HRESULT的异常:0x800A03EC for(i=0;i
for(i=0;i
可能的解决方案是
var-cellValue=(字符串)(excelWorksheet.Cells[10,2]作为Excel.Range.Value代码>
=文本(变量,“0”)
,在excel中转换for (i = 0; i < excelCell.Columns.Rows.Count; i++)
{
if (excelCell.Value2 == null)
continue;
else
excelWorksheet.Range[excelCell,Type.Missing].ToString();
}
string l_filePath = txtComparisonFile.Text;
string l_fileExt = System.IO.Path.GetExtension(l_filePath);
if (l_fileExt.CompareTo(".xls") == 0)
l_connectionString = @"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + l_filePath + ";Extended Properties='Excel 8.0;HRD=Yes;IMEX=1';"; //for below excel 2007
else
l_connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + l_filePath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1';";
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = false;
string workbookPath = l_filePath;
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = l_selectedSheet;
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range(l_comparisonSheetRange);
excelWorksheet.Columns.NumberFormat = "@";
excelWorkbook.Save();
excelWorkbook.Close();
g_objExcelHelper.g_objDtCompare = g_objExcelHelper.GetDataTable(l_connectionString, l_selectedSheet, l_comparisonSheetRange, g_objExcelHelper.g_objDtCompare);