Open excel without saving in local drive

Hi Team,

How to open excel generated using Aspose.Cells without saving the excel file in local drive? I have tried using Open method but its not opening.

Please give me idea to do this.

Hi,

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

Please first of all, download and use the latest version:
Aspose.Cells
for .NET v7.3.1.1
the Open method is now obsolete, so you will have to use latest version.

First, save your workbook into memory stream object and then load your another workbook from your memory stream object.

This way, you will not have to save your workbook on local drive.

The code below first creates a workbook, then it adds some text in cell A1 of the first worksheet, then it saves the workbook into memory stream object.

After that it creates a new workbook object from saved memory stream object and save it on local drive to check the output.

Below is a sample code how to achieve this. I have attached the output xlsx file generated by this code and screenshot for your reference.

C#

//Create a workbook from scratch
Workbook workbook = new Workbook();

//Write something in cell A1 of first worksheet
Worksheet worksheet = workbook.Worksheets[0];

Cell a1 = worksheet.Cells["A1"];
a1.PutValue("Hello Aspose!");

//Autofit columns
worksheet.AutoFitColumns();

//Now save the workbook into memory stream with xlsx format
//you do not need to save it on local drive
MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Xlsx);

//Now create your new workbook from memory stream
Workbook newBook = new Workbook(ms);

//Now save the new workbook on local drive to check the output
newBook.Save("output.xlsx", SaveFormat.Xlsx);

Screenshot:

Hi

Thanks for your reply.

In the above mentioned code. You are saving the data in memory stream then using that memory stream creating new workbook then saving that in local drive to check the output.

But i need to open the excel file without saving that in local drive. Without saving in local drive excel should directly open to view the data in excel.

Is this possible in Aspose? Please give the solution for this.

Hi,

Thanks for your clarification.

I think, that’s not possible, you will have to save your file somewhere on your local drive and then you can open it directly in Ms-Excel.

Please use the following code to open your file directly in Ms-Excel.

Please also note that Aspose.Cells is not Graphical User Interface Component, it is a File Format Component, so you cannot use it as an Excel Viewer. However, you can use Aspose.Cells for GridDesktop which will display your file in a grid on Windows Form Applications.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


System.Diagnostics.Process.Start(filePath);

After running this code, your file namely source.xlsx will automatically be opened in Ms-Excel 2010.

Yes now i am using Process.Start() to open the excel. So we need to save in local drive in some path after that only we can open the excel.

Without saving we can not open the excel right?

Hi,

Yes, your understanding is right because Ms-Excel will load file from hard drive. It cannot load it from Process memory.

What you can do is that you save your file in some temp folder e.g

D:\Documents and Settings\AHome\Local Settings\Temp</b>

is a kind of temp folder.

Then open it via Ms-Excel using the above code.