When I try to save a spreadsheet as .csv the result is blank. If I save as .xls it works as expected.
var workbook = new Workbook();
var i = workbook.Worksheets.Add();
var worksheet = workbook.Worksheets[i];
var cells = worksheet.Cells;
cells[“A1”].PutValue(“testing”);
workbook.Save(“h:\MarcieTest.csv”, SaveFormat.CSV);
// this works workbook.Save(“h:\MarcieTest.xls”);
What am I doing wrong?
Hi,
Hi,
I’m currently experiencing the same issue, with version 9.0, and the active sheet index is correctly set… here’s my code:
public static void Export(this IDataReader @this, Stream stream, string format)
{
using (var book = new Workbook())
{
book.Worksheets.Clear();
var sheet = book.Worksheets.Add("References");
// Data Table import to the worksheet, inserting from A1 cell of sheet
sheet.Cells.ImportDataReader(@this, true, 0, 0, true,
CultureInfo.InvariantCulture.DateTimeFormat.ShortDatePattern, false);
// Apply Hearder Row/First Row text to Bold
Style objStyle = book.CreateBuiltinStyle(BuiltinStyleType.Header1);
StyleFlag objStyleFlag = new StyleFlag { FontBold = true, WrapText = true };
sheet.Cells.ApplyRowStyle(0, objStyle, objStyleFlag);
// Fit columns width to contents
sheet.AutoFitColumns(new AutoFitterOptions { MaxRowHeight = 30 });
book.Save(stream, BuildSaveOptions(format));
}
}
…works fine with Excel file streams, but not CSV!
Also, using to code to export into a MemoryStream results in incomplete documents for every format!
The issue might be due to your own code as I do not see any line of code where you set the active sheet index. Please see my previous reply in the thread. If you still could not evaluate your issue, kindly create a simple console demo application (runnable), you may create DataSet and DataTable dynamically in the code, zip it and post us here to reproduce the issues (e.g blank sheet and “incomplete documents”) on our end, we will check it soon.
PS. It is better that you could use our latest version’fix: Aspose.Cells for .NET v17.8.
Thank you.