using System;
using com.lowagie.text;
using com.lowagie.text.pdf;
using System.IO;
public class TestPDF
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World");
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, new FileStream("MyPDF.pdf", FileMode.Create));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
document.add(new Paragraph("Hello World"));
// step 5: we close the document
document.close();
}
}
3 回答
存在许多用于创建PDF的C#库,这里有一些list,其中包含一些 . 我过去只使用了
iText
,我认为这是一个很好的图书馆 . 您可以轻松找到教程 . 这个one看起来不错 .对于Excel,.NET Framework已经具有内置功能,更多信息here .
您可以使用名为ExcelLibrary的库以发票Excel格式打印 . 它是在Google Code上发布的开源库,可下载here .
将简单的
DataSet
表导出为.xls
或.xlsx
有关详细信息,请查看这些Create Excel (.XLS and .XLSX) file from C#,Using C# to Create an Excel Document和How to format an Excel file using C# .
Here is an alternate also available:
NPOI library
关于NPOI的好处当然是它使您能够在代码中使用模板,然后将电子表格的副本直接发送给用户 . 模板保持不变,用户收到模板的修改副本,其中包含应用程序处理的数据 . 关注此Creating Excel spreadsheets .XLS and .XLSX in C#
您可以使用
Office Interop
在Excel工作表中创建格式 . 检查一下C# - Opening Excel Template(xlt), adding data, and saving to new worksheet(xls).
检查examples的这些列表,它们可以帮助您创建和操作pdf文档 .
搜索Telerik报告Check this