-1

I use excellibrary library in working with excel. My code is

        Workbook book = Workbook.Load(book_name);
        Workbook book_new = Workbook.Load(file_name);

        Worksheet sheet = book.Worksheets[0];
        Worksheet sheet_new = book_new.Worksheets[0];

        for (int rowIndex = 7; rowIndex <= 2235; rowIndex++)
        {
            Console.WriteLine(sheet.Cells[rowIndex, ost_index] + " " + sheet_new.Cells[rowIndex, ost_index]);

            sheet.Cells[rowIndex, ost_index] = sheet_new.Cells[rowIndex, ost_index];
            sheet.Cells[rowIndex, price_index] = sheet_new.Cells[rowIndex, price_index];
        }

        book.Save(book_name);

In this code I copy two cols from one file to another. And there is a problem. this excel file has a lot of style like hyperlink etc. When I open the file after using program I see a window with the text Unable to read file. After clicking "ok... ok... ok..." I see file without formatting(no color, no style and so on). How can I repair it? P.S. sorry for my English.

Shashank Shekhar
  • 3,958
  • 2
  • 40
  • 52
zMeFz
  • 38
  • 5
  • you are saving the book..but where are you closing and disposing of the created objects..? – MethodMan Mar 23 '15 at 20:36
  • can you write how to do this? – zMeFz Mar 23 '15 at 20:37
  • you have the code write there in front of you are you familiar with how to debug and use the `Intellesense` – MethodMan Mar 23 '15 at 20:38
  • Excuse me, but I don't understand: which object should i close and dispouse here? – zMeFz Mar 23 '15 at 20:42
  • do you have a method Workbook.Close() or dispose ? call it for both instances of Workbook after the save call. – Shashank Shekhar Mar 23 '15 at 20:47
  • I try to open xls file after closing program. And closing there is nothing here as I thing, isn't it? – zMeFz Mar 23 '15 at 20:48
  • "ExcelLibrary.SpreadSheet.Workbook" does not contain a definition for "Close" – zMeFz Mar 23 '15 at 20:49
  • are you using Microsoft.Interop..? the objects are disposed differently also there are examples on the internet.. I would respectfully suggest a simple google search ... and any object that you create an instance of you should be nulling out or disposing or releasing etc... – MethodMan Mar 23 '15 at 20:58
  • But I can't disposed this objects becouse ".Close()" isn't work and I know nothing about this library. Maybe you can suggest me another library for excel? Or help in what should I write to close it. Sorry for my programming level. I just learning. – zMeFz Mar 23 '15 at 21:04
  • This might help you: http://stackoverflow.com/questions/8107610/cant-open-excel-file-generated-with-excellibrary I would suggest looking for another library, the one you are using hasn't been updated for a long time now – Shashank Shekhar Mar 23 '15 at 21:14
  • Okay, I gonna use newer library if i find it. Thank you for advice – zMeFz Mar 23 '15 at 21:24
  • sheet.Cell[...].Value = sheet_new.Cells[...].Value; – Hans Passant Mar 23 '15 at 21:24
  • sheet.Cell[...].Value = sheet_new.Cells[...].Value; it isn't work. I gonna find new library. Big thanks to Shekhar. Can somebody recommend me a library? I would be very grateful :) – zMeFz Mar 23 '15 at 21:38

1 Answers1

0

This seems to be a known bug in the library, and since the library hasn't been updated since the reporting, your best bet at this point is to switch to another library.

Shashank Shekhar
  • 3,958
  • 2
  • 40
  • 52