Aspose Cells - get excel from csv string

We just bought Aspose Cells .NET to create Excel files in an ASP.NET application.
Now we have to convert a CSV string to a PDF file (without using a text file on disk). Here is my sample code:

//Sample
String csv = "Col1;Col2;Col3;\n"
+ "53;34;23;\n"
+ "33;123;221;\n"

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

TxtLoadOptions options = new TxtLoadOptions(LoadFormat.CSV);
options.Separator = Convert.ToChar(";");

Cells cells = worksheet.Cells;
//Import not from file but from string
cells.ImportCSV(csv, options, 0, 0);

workbook.Save("test.xlsx", FileFormatType.Xlsx, SaveType.OpenInExcel, this.Response);

Do you have any idea how to solve this problem?

Thanks a lot in advanced

Martin

Hi,


Please get the CSV contents into streams to be used into ImportCSV method, see the updated sample code for your reference that works fine:
e.g
Sample code:

//Sample
String csv = “Col1;Col2;Col3;\n” + “53;34;23;\n” + “33;123;221;\n”;
byte[] byteArray = Encoding.ASCII.GetBytes(csv);
MemoryStream stream = new MemoryStream(byteArray);

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
TxtLoadOptions options = new TxtLoadOptions(LoadFormat.CSV);
options.Separator = Convert.ToChar(";");
Cells cells = worksheet.Cells;
//Import not from file but from string
cells.ImportCSV(stream, options, 0, 0);
//…


Thank you.



Thank you very much, you both.

Martin

Hi,


Good to know that it sorts our your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.