Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need to Export to the below formats.
Please share some link through which i can achieve this. The code needs to be in C#.

• Tab delineated CSV
• TSV
• TSV for excel
• Excel
• PDF
Posted

See the following:
 
Share this answer
 
hi , we have did one register form , if the user register then the details will shows u in pdf format to save the data as hardcopy , i.e print out ...


try this code if u can, but make some modifications as per your requirements,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using MySql.Data.MySqlClient;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using iTextSharp.text;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using BAL;

namespace Subsidy
{
public partial class WebForm1 : System.Web.UI.Page
{
DataTable dt;
ClassBAL obj = new ClassBAL();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string aadhaar = Session["adharno"].ToString(); //"521207150960"; //
dt = obj.getfarmerinfo1(aadhaar);

string sno = dt.Rows[0]["SNo"].ToString();
Session["sno"] = sno.ToString();
lbladhar.Text = dt.Rows[0]["AadhaarID"].ToString();
lbluname.Text = dt.Rows[0]["FarmerName"].ToString();
lblfathername.Text = dt.Rows[0]["FatherOrHusbandName"].ToString();
lblvillage.Text = dt.Rows[0]["VillageName"].ToString();
lblmandal.Text = dt.Rows[0]["MandalOrDistrict"].ToString();
lblssidno.Text = dt.Rows[0]["SSIDNo"].ToString();
lblsubcast.Text = dt.Rows[0]["CastDetails"].ToString();
lblsurveyno.Text = dt.Rows[0]["LandSurveyNumber"].ToString();
lblpassbookno.Text = dt.Rows[0]["PattaPassbookNumber"].ToString();
lblprocate.Text = dt.Rows[0]["Requiredsubsidycategory"].ToString();
lblproname.Text = dt.Rows[0]["Requiredproduct"].ToString();
lblprice.Text = dt.Rows[0]["ActualPrice"].ToString();
lblsubsidy.Text = dt.Rows[0]["SubsidyPrice"].ToString();
lblmobile.Text = dt.Rows[0]["MobileNumber"].ToString();

DateTime dtime = new DateTime();
dtime = DateTime.Now;
string DTime = dtime.ToString();
Session["DTime"] = DTime.ToString();
}
}

protected void btnprint_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlPerson.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
//Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
Document pdfDoc = new Document(PageSize.A3, 100f, 10f, 10f, 10f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();

////pdf adding to table format
PdfPTable table1 = new PdfPTable(2);
//empty space
string space = "\n,\n"; Paragraph para2 = new Paragraph(space);
para2.Alignment = Element.ALIGN_CENTER; pdfDoc.Add(para2);
//adding Header
string Header = @"REGISTERED SUBSIDY DETAILS";
Paragraph para = new Paragraph(Header);
para.Alignment = Element.ALIGN_CENTER;
pdfDoc.Add(para);
//DateTime
string dtime = Session["DTime"].ToString();
Paragraph para1 = new Paragraph(dtime);
para1.Alignment = Element.ALIGN_RIGHT;
pdfDoc.Add(para1);
//Serial No
string SNo = "Invoice Number :";
Paragraph parasno = new Paragraph(SNo); parasno.Alignment = Element.ALIGN_LEFT; pdfDoc.Add(parasno);
string sno = Session["sno"].ToString();
Paragraph parasno1 = new Paragraph(sno); parasno1.Alignment = Element.ALIGN_LEFT; pdfDoc.Add(parasno1);

//empty space
string space1 = "\n,\n"; Paragraph para3 = new Paragraph(space1);
para3.Alignment = Element.ALIGN_CENTER; pdfDoc.Add(para3);

//cell11
PdfPCell cell11 = new PdfPCell();
cell11.AddElement(new Paragraph("Aadhaar Card Number :"));
table1.AddCell(cell11);
PdfPCell cell12 = new PdfPCell();
cell12.AddElement(new Paragraph(lbladhar.Text));
table1.AddCell(cell12);
//cell21
PdfPCell cell21 = new PdfPCell();
cell21.AddElement(new Paragraph("Farmer Name :"));
table1.AddCell(cell21);
PdfPCell cell22 = new PdfPCell();
cell22.AddElement(new Paragraph(lbluname.Text));
table1.AddCell(cell22);
//cell31
PdfPCell cell31 = new PdfPCell();
cell31.AddElement(new Paragraph("Father/Husband Name :"));
table1.AddCell(cell31);
PdfPCell cell32 = new PdfPCell();
cell32.AddElement(new Paragraph(lblfathername.Text));
table1.AddCell(cell32);
//cell41
PdfPCell cell41 = new PdfPCell();
cell41.AddElement(new Paragraph("Village Name :"));
table1.AddCell(cell41);
PdfPCell cell42 = new PdfPCell();
cell42.AddElement(new Paragraph(lblvillage.Text));
table1.AddCell(cell42);
//cell51
PdfPCell cell51 = new PdfPCell();
cell51.AddElement(new Paragraph("Mandal/District Name :"));
table1.AddCell(cell51);
PdfPCell cell52 = new PdfPCell();
cell52.AddElement(new Paragraph(lblmandal.Text));
table1.AddCell(cell52);
//cell61
PdfPCell cell61 = new PdfPCell();
cell61.AddElement(new Paragraph("S.S.I.D.No :"));
table1.AddCell(cell61);
PdfPCell cell62 = new PdfPCell();
cell62.AddElement(new Paragraph(lblssidno.Text));
table1.AddCell(cell62);
//cell71
PdfPCell cell71 = new PdfPCell();
cell71.AddElement(new Paragraph("Reservation Category :"));
table1.AddCell(cell71);
PdfPCell cell72 = new PdfPCell();
cell72.AddElement(new Paragraph(lblsubcast.Text));
table1.AddCell(cell72);
//cell81
PdfPCell cell81 = new PdfPCell();
cell81.AddElement(new Paragraph("Land Survey Number :"));
table1.AddCell(cell81);
PdfPCell cell82 = new PdfPCell();
cell82.AddElement(new Paragraph(lblsurveyno.Text));
table1.AddCell(cell82);
//cell91
PdfPCell cell91 = new PdfPCell();
cell91.AddElement(new Paragraph("Patta Passbook Number :"));
table1.AddCell(cell91);
PdfPCell cell92 = new PdfPCell();
cell92.AddElement(new Paragraph(lblpassbookno.Text));
table1.AddCell(cell92);
//cell101
PdfPCell cell101 = new PdfPCell();
cell101.AddElement(new Paragraph("Product Category :"));
table1.AddCell(cell101);
PdfPCell cell102 = new PdfPCell();
cell102.AddElement(new Paragraph(lblprocate.Text));
table1.AddCell(cell102);
//cell111
PdfPCell cell111 = new PdfPCell();
cell111.AddElement(new Paragraph("Product Name :"));
table1.AddCell(cell111);
PdfPCell cell112 = new PdfPCell();
cell112.AddElement(new Paragraph(lblproname.Text));
table1.AddCell(cell112);
//cell121
PdfPCell cell121 = new PdfPCell();
cell121.AddElement(new Paragraph("Product Actual Price :"));
table1.AddCell(cell121);
PdfPCell cell122 = new PdfPCell();
cell122.AddElement(new Paragraph(lblprice.Text));
table1.AddCell(cell122);
//cell131
PdfPCell cell131 = new PdfPCell();
cell131.AddElement(new Paragraph("Product Subsidy Price :"));
table1.AddCell(cell131);
PdfPCell cell132 = new PdfPCell();
cell132.AddElement(new Paragraph(lblsubsidy.Text));
table1.AddCell(cell132);
//cell141
PdfPCell cell141 = new PdfPCell();
cell141.AddElement(new Paragraph("Mobile Number :"));
table1.AddCell(cell141);
PdfPCell cell142 = new PdfPCell();
cell142.AddElement(new Paragraph(lblmobile.Text));
table1.AddCell(cell142);

pdfDoc.Add(table1);

// htmlparser.Parse(sr);
pdfDoc.Close();
// Response.Write(pdfDoc);
// Response.End();
}

protected void btnback_Click(object sender, EventArgs e)
{
Response.Redirect("DAOHomePage.aspx");
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900