Is Workbook / worksheet empty or default

Hi

I am looking for a way to find out if a workbook contains any information or not . Or maybe a way to find if the workbook is just the default empty workbook that opens with excel and has not been modified.Anything will be good . (I need this to know if I can override the current workbook without fear of loosing any valueble information .

I would be interested if you know of a way both with your API and with Microsoft.Office.Interop.Excel Api since I am using both together (some of my code does not have access to your api and some does)

Thanks.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

If you want to check that worksheet contains any information or not, then please check if worksheet.Cells.Count is greater than 0.

If it is 0, it means, worksheet is empty.

If it is >0, it means, worksheet has some information.

Hopefully, it will be helpful for your needs.

Thanks for the reply , just one problem

assuming I have an object of type _Workbook (Microsoft.Office.Interop.Excel) , what is the easiest way to convert it into an Aspose Workbook .

I prefer not to save it to disk and open it .

Hi,

If you could save your interop workbook into memory stream, then you can easily convert it into aspose workbook.

You do not need to save anything on disk, only RAM will be used in this conversion.

For example, suppose ms is a MemoryStream object in which you have saved your interop workbook, so you can convert it into your aspose workbook like this.

C#


MemoryStream ms = new MemoryStream();


//Save your interop worbook into memory steam in the next lines

//--------write your own code here-------


//Now convert it into Aspose workbook

ms.Position = 0;

Workbook workbook = new Workbook(ms);


Hi

Thats exactly what I though of doing but I couldnt really find a way to save a _Workbook object into memory stream. Would you know ?

Thanks.

Hi,

It seems like its a limitation of Interop workbook, you will have to save it on to disk first and then create an aspose workbook using filestream.

Please refer to these questions.
( c# - Is there a way to get byte[] from ExcelWorkBook without saving it to disk first - Stack Overflow )
( How to write an Excel workbook to a MemoryStream in .NET? - Stack Overflow )

You might search on the internet if you could directly save it to memory stream or byte array.

Ok Thanks.