C# ListView to PDF

Technical support for Spire.DataExport

Moderators: iceblue support, DataExport, Manager

C# ListView to PDF

Postby ProgramForFun » Sat Jan 30, 2016 12:29 am

Greetings

I was testing "Spire.DataExport for .NET" and trying to create a PDF from a ListView in C#. I was able to work my way through the example exporting to Microsoft Excel, however, this didn't work out exporting to PDF format (Export Data from Listview to PDF in C#, VB.NET) because it's required to use the oleDbConnection. Most of the tutorials pretty much work with databases and not so much with a list view.

Are there any working examples to export from a list view into a PDF document for C#?
ProgramForFun
 
Posts: 2
Joined: Sat Jan 30, 2016 12:06 am

Re: C# ListView to PDF

Postby amy.zhao » Mon Feb 01, 2016 8:03 am

Hi,

Thanks for your posting and using our component.
According to your requirement, I recommend you to use Spire.Xls component.
Code: Select all
DataTable table = new DataTable();
foreach (ListViewItem item in listView1.Items)
           {
                table.Columns.Add(item.ToString());
                foreach (var it in item.SubItems)
                table.Rows.Add(it.ToString());
            }
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.InsertDataTable(table, true, 1, 1);
sheet.Range.BorderAround();
sheet.Range.BorderInside();
book.SaveToFile("result.pdf",FileFormat.PDF);


Best Regards,
Amy
E-iceblue support team
User avatar
amy.zhao
 
Posts: 2202
Joined: Wed Jun 27, 2012 8:50 am

Re: C# ListView to PDF

Postby amy.zhao » Thu Feb 04, 2016 8:49 am

Hi,

Has your issue been resolved?
Thanks for your feedback.

Best Regards,
Amy
E-iceblue support team
User avatar
amy.zhao
 
Posts: 2202
Joined: Wed Jun 27, 2012 8:50 am

Re: C# ListView to PDF

Postby ProgramForFun » Sun Feb 07, 2016 9:37 pm

Sorry for not responding right away, but I didn't get an email that my post was updated. Just selected the "Notify me when a reply is posted" check box.

Thank you very much, but Spire.Xls is overkill for me because I only needed to generate rows and columns with supported information along with page numbering as well as minimal functionality with Excel. Originally, I was using iTextsharp and had a very difficult time trying to add page numbers to the PDF, but recently figured it out.

My interest is in "Spire.DataExport for .NET" working with Excel, PDF files and listViews. As mentioned previously, most of your tutorials are derived around database connectivity and the code that is available for PDF and ListViews doesn't work.

Do you have anything that works with the advertised product "Spire.DataExport" and ListViews?
ProgramForFun
 
Posts: 2
Joined: Sat Jan 30, 2016 12:06 am

Re: C# ListView to PDF

Postby Gary.zhang » Mon Feb 08, 2016 7:14 am

Hello,

Here are some sample codes for your reference. Hope it is helpful.
Code: Select all
Spire.DataExport.PDF.PDFExport PDFExport = new Spire.DataExport.PDF.PDFExport();
PDFExport.DataSource = Spire.DataExport.Common.ExportSource.ListView;
PDFExport.ListView = this.listView1;
PDFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
PDFExport.SaveToFile("20110223.pdf");

Sincerely,
Gary
E-iceblue support team
User avatar
Gary.zhang
 
Posts: 1362
Joined: Thu Apr 04, 2013 1:30 am


Return to Spire.DataExport

Who is online

Users browsing this forum: No registered users and 0 guests