0

Good morning, I'm trying to create Excel file in C#, I looked to the way to do it, and I found a tutorial, here is the code I tried:

        Microsoft.Office.Interop.Excel.Application excel;  
        Microsoft.Office.Interop.Excel.Workbook worKbooK;
        Microsoft.Office.Interop.Excel.Worksheet worksheet;  
        Microsoft.Office.Interop.Excel.Range celLrangE;

        excel = new Microsoft.Office.Interop.Excel.Application();
        excel.Visible = false;
        excel.DisplayAlerts = false;  

Well, I have this error on initializing the variable excel

COM object with CLSID '{00020819-0000-0000-C000-000000000046}' cannot be created due to the following error: Class not registered .

I searched for this error, what I found is solution to problems in cases, but none has the problem in Excel operations, so ... ?

PS: I'm creating an application for Windows Mobile 6.5, but I think it's supposed to work on it, if it works of course.

For the vote down hungers, well ... unleash yourselves, I can't stop you :) but believe me, I tried a lot, there's so many ways to create Excel files, but whatever I try, the same error is summoning, I think it's not the problem of library, or code, but something else I can't find.

Thanks in advance !

STLDev
  • 5,950
  • 25
  • 36
SGA
  • 15
  • 7
  • Just curious, but what "bit-ness" of Microsoft Office do you have installed? 32-bit or 64-bit? Also, I feel a bit silly for asking, but have you tried running Excel on the computer? Does it work? – STLDev Apr 04 '17 at 14:11
  • Is that matters? because I use the application on the phone, when I press button (which has the press event, the code above), the error comes on the line of `excel = .... `, I'm using a Windows 7 64 bits with MS Visual Studio 2008, the phone is on Windows Mobile 6.5 – SGA Apr 04 '17 at 14:16
  • So, your code is attempting to interop with Microsoft Excel. Unless Microsoft Excel is installed and working on your device, how will your program inter-operate with it? – STLDev Apr 04 '17 at 14:17
  • Possible duplicate of [Class not registered error when creating Excel workbook in C#](http://stackoverflow.com/questions/20397506/class-not-registered-error-when-creating-excel-workbook-in-c-sharp) – Thalles Noce Apr 04 '17 at 14:19
  • Ah, you mean on the device? of course excel is installed on it, and works very well – SGA Apr 04 '17 at 14:19
  • @Thalles Noce, my application is running on a mobile device, I've found this topic, but it doesn't match to my case :/ – SGA Apr 04 '17 at 14:21
  • http://stackoverflow.com/questions/20975105/80040154-class-not-registered-exception-from-hresult – OldProgrammer Apr 04 '17 at 14:21
  • @OldProgrammer, I repeat, the application is running on a mobile device ! Even the reference (library on `C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12`) is a x86, which I suppose corresponding the the office on the device – SGA Apr 04 '17 at 14:29

1 Answers1

0

Maybe use another Library: https://code.google.com/archive/p/excellibrary/

Found in this question: Create Excel (.XLS and .XLSX) file from C#

Community
  • 1
  • 1
Thalles Noce
  • 791
  • 1
  • 9
  • 20
  • Thanks for the answer, this code works, but the file can't be opened, I tried the "open and repair", but it doesn't work too, I'm using Office 2013, But when I tried to open it with Office 2007 "Want you to read the file anyway" and it was opened, is there a way to create a normal correct file format? Anyway, thank you – SGA Apr 04 '17 at 14:54