C#中gridview 的数据汇出到PDF中怎么实现啊?

object_hellojie 2011-02-11 05:12:28
C#中gridview 的数据汇出到PDF中怎么实现啊?最好提供demo或者下载例子
...全文
291 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
crackdung 2011-02-12
  • 打赏
  • 举报
回复
免費的,功能強大的,能滿足你所有導出功能需要使用這個
http://www.e-iceblue.com/Download/download-dataexport-for-net-now.html


其它樓上說的只是單調的
wwfgu00ing 2011-02-12
  • 打赏
  • 举报
回复
Response.Clear();                Response.ContentType = "application/PDF";                Response.AddHeader("content-disposition", "attachment;filename=test.pdf");                Response.Charset = ""; ReportDocument l_crReportDocument;                l_crReportDocument = new ReportDocument();                ExportOptions l_crExportOptions = new ExportOptions();                DiskFileDestinationOptions l_crDiskFileDestinationOptions = new DiskFileDestinationOptions(); DataTable test=new DataTable("test"); // Remember the test datatable should have same coulmn names as that of .xsd file which you will use for report creating and also datatable name should be same as that of .xsd datatble.l_crReportDocument.Load(Server.MapPath("Report/test.rpt"));l_crReportDocument.SetDataSource(ManagerChequeDataTable);                MemoryStream l_oStream;                l_oStream = (MemoryStream)l_crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);                Response.Clear();                Response.Buffer = true;                Response.ContentType = "application/PDF";                Response.BinaryWrite(l_oStream.ToArray());                Response.End(); 
  • 打赏
  • 举报
回复
wuyq11 2011-02-11
  • 打赏
  • 举报
回复
using iTextSharp.text;

using iTextSharp.text.pdf;

using iTextSharp.text.html;

using iTextSharp.text.html.simpleparser;





protected void btnExportPDF_Click(object sender, EventArgs e)

{

Response.ContentType = "application/pdf";

Response.AddHeader("content-disposition",

"attachment;filename=GridViewExport.pdf");

Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

GridView1.AllowPaging = false;

GridView1.DataBind();

GridView1.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());

Document pdfDoc = new Document(PageSize.A4, 10f,10f,10f,0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse(sr);

pdfDoc.Close();

Response.Write(pdfDoc);

Response.End();

}

http://www.dotnetspider.com/forum/109866-Gridview-PDF.aspx
xinxing130 2011-02-11
  • 打赏
  • 举报
回复
楼主 可以用下wkhtmltopdf.exe这个生成pdf插件 简单的需求生成没什么问题很方便
子夜__ 2011-02-11
  • 打赏
  • 举报
回复
itextsharp
/// <summary>

/// 转换GridView为PDF文档

/// </summary>

/// <param name="pobjGrdv">要转换的GridView</param>

/// <param name="PDFFileName">在服务器端保存PDF时的文件名</param>

/// <param name="FontPath">PDF甩用字体所在的物理路径</param>

/// <param name="FontSize">字体大小</param>

/// <returns>返回调用是否成功</returns>

public static void ConvertGrdiViewToPdf(GridView pobjGrdv, string PDFFileName, string FontPath, float FontSize)

{

//在服务器端保存PDF时的文件名

string strFileName = PDFFileName + ".pdf";

// GridView的所有数据全输出

pobjGrdv.AllowPaging = false;

//**************************

int countColumns = pobjGrdv.Columns.Count;

int countRows = pobjGrdv.Rows.Count;

if (countColumns != 0 && countRows != 0)

{

//初始化一个目标文档类

//Document document = new Document();

//竖排模式,大小为A4,四周边距均为25

Document document = new Document(PageSize.A4, 0, 0, 0, 0);

//横排模式,大小为A4,四周边距均为50

//Document doc = new Document(PageSize.A4.rotate(),50,50,50,50);

//调用PDF的写入方法流

//注意FileMode-Create表示如果目标文件不存在,则创建,如果已存在,则覆盖。

PdfWriter writer = PdfWriter.GetInstance(document,

new FileStream(HttpContext.Current.Server.MapPath(strFileName), FileMode.Create));

try

{

//创建PDF文档中的字体

BaseFont baseFont = BaseFont.CreateFont(

FontPath,

BaseFont.IDENTITY_H,

BaseFont.NOT_EMBEDDED);

//根据字体路径和字体大小属性创建字体

Font font = new Font(baseFont, FontSize);

// 添加页脚

//HeaderFooter footer = new HeaderFooter(new Phrase(footertxt), true);

HeaderFooter footer = new HeaderFooter(new Phrase("-- ", font), new Phrase(" --", font));

footer.Border = Rectangle.NO_BORDER; // 不显示两条横线

footer.Alignment = Rectangle.ALIGN_CENTER; // 让页码居中

document.Footer = footer;

//打开目标文档对象

document.Open();

//**************************

//根据数据表内容创建一个PDF格式的表

PdfPTable table = new PdfPTable(countColumns);

//iTextSharp.text.Table table = new iTextSharp.text.Table(pobjGrdv.Columns.Count);

// 添加表头

// 设置表头背景色

//table.DefaultCell.BackgroundColor = Color.GRAY; // OK

//table.DefaultCell.BackgroundColor =

//(iTextSharp.text.Color)System.Drawing.Color.FromName("#3399FF"); // NG

table.DefaultCell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;

//table.DefaultCell.BackgroundColor = System.Drawing.Color.DodgerBlue;

// 添加表头

for (int j = 0; j < countColumns; j++)

{

table.AddCell(new Phrase(pobjGrdv.HeaderRow.Cells[j].Text, font)); // OK

}

// 告诉程序这行是表头,这样页数大于1时程序会自动为你加上表头。

table.HeaderRows = 1;

// 添加数据

// 设置表体背景色

table.DefaultCell.BackgroundColor = Color.WHITE;

//遍历原gridview的数据行

for (int i = 0; i < countRows; i++)

{

for (int j = 0; j < countColumns; j++)

{

table.AddCell(new Phrase(pobjGrdv.Rows[i].Cells[j].Text, font));

}

}

//在目标文档中添加转化后的表数据

document.Add(table);

}

catch (Exception)

{

throw;

}

finally

{

//关闭目标文件

document.Close();

//关闭写入流

writer.Close();

}

// 弹出提示框,提示用户是否下载保存到本地

try

{

//这里是你文件在项目中的位置,根目录下就这么写

String FullFileName = System.Web.HttpContext.Current.Server.MapPath(strFileName);

FileInfo DownloadFile = new FileInfo(FullFileName);

System.Web.HttpContext.Current.Response.Clear();

System.Web.HttpContext.Current.Response.ClearHeaders();

System.Web.HttpContext.Current.Response.Buffer = false;

System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";

System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="

+ System.Web.HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));

System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);

}

catch (Exception)

{

throw;

}

finally

{

System.Web.HttpContext.Current.Response.Flush();

System.Web.HttpContext.Current.Response.End();

}

}

else

{

System.Web.HttpContext.Current.Response.Write

("<script type='text/javascript'>alert('数据为空,不值得导出pdf!');</script>");

}

}

//然后,在要调用转换的按钮的事件代码中调用就可以了

//假设传进去的GridView的名字为GridView1

//假设要保存的文件名为GridView的ID

//假设字体使用simsun (请注意根据你电脑的实际情况来选择目录)

//假设字号选择14

//GridViewToPdf.ConvertGridViewToPdf(this.GridView1,

//this.GridView1.ID.ToString(), "c:\\winnt\\FONTS\\simsun.ttc,1", 14);

#endregion

}


全文参考
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,分析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性分析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性分析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网提升稳定性的内在机理;③复现顶刊论文的阻抗分析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据分析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧