Problem in Converting CSV to Excel

Hi,

I have a .tcv file which is to be converted to Excel and then to PDF.

What I tried is -

  • Open .tcv file as "tabdelimited"
  • Save it as ".csv"
  • Open .csv file
  • Save it as ".xls"
  • Open the .xls file
  • Create its .xml as AsposePdf
  • Bind the xml
  • save it as pdf

Now, the problem is the Pdf generated isn't in the correct format. I have attached all the files created at each step.

Thanks

Kunal

Dear Kunal,

Thanks for considering Aspose.Cells.

Please provide me your code example. Also attach your .tcv file. I will investigate your issue.

Thanks for the quick reply. Attached are the .tcv and its .xls file.

Below is the code I am using:

//convert TCV to CSV
Workbook local_workbook = new Workbook();
local_workbook.Open(@"C:\sampleTcv.tcv", FileFormatType.TabDelimited);
local_workbook.Save(@"C:\sampleCsv.csv", SaveFormat.CSV);

//convert CSV to XLS
Workbook local_workbook = new Workbook();
local_workbook.Open(@"C:\sampleCsv.csv", FileFormatType.CSV);
local_workbook.Save(@"C:\sampleXls.xls", SaveFormat.Excel97To2003);

//convert XLS to XML
Workbook local_workbook = new Workbook();
local_workbook.Open(@"C:\sampleXls.xls", FileFormatType.Excel97To2003);
local_workbook.Save(@"C:\sampleXml.xml", FileFormatType.AsposePdf);

//convert XML to PDF
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(@"C:\sampleXml.xml", null);
pdf.Save(@"C:\samplePdf.pdf");

This is the kind of code I am using. Actually I am dealing with memory stream instead of actual files. The file path here is just for the sake of dummy code.

Thanks Again

Kunal

Also if you can throw some light on formatting so that I can create the xls as shown in the sample from the given tcv file.

Thanks

Dear Kunal,

Our latest Aspose.Cells for .NET can save csv files directly to pdf.You can use e.g v5.2.1.1


This is the sample code shared by my colleague.

Workbook wb = new Workbook(“e:\test2\csvfile.csv”, new LoadOptions(LoadFormat.CSV));
wb.Save(“e:\test2\outdest.pdf”);

Please also see this document for more help.

Converting to PDF Files

Dear Kunal,

You can download it from this link. Aspose.Cells. v5.2.1.1

Thanks for the support.

I need the xls file as well that is why I have to stick to the old procedure only. Thanks anyways.

Now, excel.xls is the file created by Aspose.Cell and InvoiceSampleImage.xls is the sample template. What can be done to create an xls file like InvoiceImageSample.xls?

Thanks

Kunal

Hi,

For InvoiceImageSample.xls, you are merging the cells. Please refer to this document.

Merging / UnMerging Cells in the Worksheet

Also, for styling the cell with pattern, please see this code and output file generated by it.

C#


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.Worksheets[0];


Cell a1 = worksheet.Cells[“A1”];


Style a1Style = a1.GetStyle();

a1Style.Pattern = BackgroundType.Gray25;

a1.SetStyle(a1Style);


workbook.Save(“f:\downloads\output.xlsx”, SaveFormat.Xlsx);