We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Saving workbook to CSV only saved one worksheet

Hi,

when saving a workbook to CSV format, only the first workbook gets saved. Is there a way to save all worksheets to a CSV file, or control which worksheet is actually saved?

I'm using this simple code:

Aspose.Cells.Workbook doc = new Workbook(fileName);
doc.Save(outputFilename, Aspose.Cells.SaveFormat.CSV);

Also, it appears that if there are textboxes in the worksheet, the value in the textboxes is not saved in the CSV file. Is there a way for me to access these, and append them to my CSV file manually?

Regards

Thomas

Hi,

Thanks for your posting.

Please provide us your sample xls/xlsx file and the output file. We will investigate this issue.

Hi,

sure, it is attached to this post.

Regards

Thomas

Hi,

Please use the following code to access the Shape (TextBox)'s text. Once you have access to text, you can manually insert it at the last cell. Then you can save the workbook in csv format.

Please see the output csv file created by the code

C#


string fpath = @“F:\Downloads\Book1.xls”;


//Open the source workbook

Workbook wk = new Workbook(fpath);


//Access the worksheet

Worksheet sheet = wk.Worksheets[0];


//Access the shape text

Shape shp = sheet.Shapes[0];


//Insert the shape text in cell A3

sheet.Cells[“A3”].PutValue(shp.Text);


//Save the workbook in csv.

//Now the shape text will be appended at the end of the csv file

wk.Save(fpath + “.out.csv”, SaveFormat.CSV);

Hi,


Regarding your question about exporting multiple worksheets to CSV. You can only export the Active Worksheet to CSV using MS Excel and Aspose.Cells behaves exactly the same. That means, when you save the workbook to CSV, only the active worksheet is exported out.
Although, using Licensed Copy of Aspose.Cells API you may set any worksheet as active. Below is the sample source code for your reference.

C# Sample Code:

var book = new Workbook(“C:\temp\Book1.xls”);

var option = book.SaveOptions;

option.SaveFormat = SaveFormat.CSV;

for (int i = 0; i < book.Worksheets.Count; i++)

{

book.Worksheets.ActiveSheetIndex = i;

book.Save(“C:\temp\out-”+i+".csv", option);

}

Hello Support,

We are evaluating the demo version of Aspose.Cells, and one of the features we want to evaluate is to save a specific worksheet as csv file.

We've tried the sample code provided in this thread but it always seems to save the original active worksheet and we are not able to save another worksheet.

Any advice?

Thank you.

Eliot Gorman

Hi,

I followed the sample that Barbar gave where you would set the ActiveWorksheet. I saved each worksheet to a stream, and combined them all into a single CSV file. Everything works perfectly.

Regards

Thomas

I just noticed that Barbar wrote this: "Although, using Licensed Copy of Aspose.Cells API you may set any worksheet as active." Perhaps your problem is that you're not using a licens version of Aspose.Cells? Make sure you loade the license before making any calls to the Aspose.Cells namespace.

Regards

Thomas

Hi Thomas,

We are using the trial version, and are trying to simply export a single worksheet.

When we simply use the Save to CSV function, it defaults to one worksheet (assumed "ActiveWorksheet").

However, when we set the ActiveWorksheet to something other than the default (when it opened), the Save to CSV still saves the original default worksheet - not the worksheet that we have specified as Active.

The documentation states something about this working in the licensed version only, so we are wondering if that is why we are not able to export only a specific worksheet?

I've requested a temp license to see if that will alleviate the issue.

Thank you.

Eliot

Thanks for the quick response Thomas, we've received a temporary license so will try using that.

Best Regards,

Eliot