Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C语言在Excel中将单元格内容转换为字符串数据类型#_C# - Fatal编程技术网

C# 使用C语言在Excel中将单元格内容转换为字符串数据类型#

C# 使用C语言在Excel中将单元格内容转换为字符串数据类型#,c#,C#,在下面的代码中,我得到了这种异常 Data_Consistency.exe中发生类型为“System.Runtime.InteropServices.COMException”的未处理异常 其他信息:来自HRESULT的异常:0x800A03EC for(i=0;i

在下面的代码中,我得到了这种异常

Data_Consistency.exe中发生类型为“System.Runtime.InteropServices.COMException”的未处理异常 其他信息:来自HRESULT的异常:0x800A03EC

for(i=0;i
可能的解决方案是

  • 从单元格中获取值:

    var-cellValue=(字符串)(excelWorksheet.Cells[10,2]作为Excel.Range.Value

  • 再次写入单元格(已写入字符串) 或者编写
    =文本(变量,“0”)
    ,在excel中转换

  • 这对我有用。。。。。。。 {

    字符串l_connectionString=“”

    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);