C #, create excel 97-2003 (.xls) Interop

using Excel = Microsoft.Office.Interop.Excel;

I need to save an excel file (.xls) from my datagridview. Everything works fine, writing data, changing cell format, etc. But the problem arises when saving the document.

string format = "yyyy_MM_dd_HH-mm";
string pathtoexport = @"C:\DM\SMS\Przychodzace\Znalezione_SMS_" + DateTime.Now.ToString(format) + ".xls";
oWB.SaveAs(pathtoexport, Excel.XlFileFormat.xlWorkbookNormal, missing, missing,
      false, false, Excel.XlSaveAsAccessMode.xlNoChange,
      missing, missing, missing, missing, missing);
    }

OK, a few days ago it worked, but now it can only say

HRESULT: 0x800A03EC "}

I need .xls to import it into SQL. Any tips?


Before the problem was in Excel.XlFileFormat.xlWorkbookDefault, when Iv changed it to Normal, everything was fine. Now it does not work. LOST a lot of time to process it myself using Google, but I couldn’t.

oWB.SaveAs(MyFile + @"C:\SMS\XMLCopy.xls",
      Excel.XlFileFormat.xlWorkbookNormal, missing, missing,
      false, false, Excel.XlSaveAsAccessMode.xlNoChange,
      missing, missing, missing, missing, missing);
+3
source share
5 answers
 string format = "yyyy_MM_dd_HH-mm";
        string pathtoexport = "C:\\DM\\SMS\\Przychodzace\\Znalezione_SMS_" + DateTime.Now.ToString(format) + ".xls";

        oWB.SaveAs(pathtoexport, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 

. .

+3

Excel.XlFileFormat.xlWorkbookDefault

+2

. , ? ( , , ), ?

- Excel -, ?

0

/ , Aspose.Cells, Excel , Office .

, .

0

Interop. , , ? - . , , ​​ .

, dev → test → prod - .

, .

( ). ?

0

Source: https://habr.com/ru/post/1780845/


All Articles