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?
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
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.
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.
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.
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.
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.