tab 1
此演示向您展示如何在 pdf 文档中创建包含指定数据的表格。
data
e-iceblue
option
downloads
如果这不是您想要的 demo,您可以通过填写表格获取免费定制 demo。
如您有与我们产品相关的其他技术问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。;销售相关的问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。。
tab 2
import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import com.spire.pdf.grid.pdfgrid;
import com.spire.pdf.grid.pdfgridcell;
import com.spire.pdf.grid.pdfgridrow;
import java.awt.*;
import java.util.list;
public class pdftabledemo {
public void createtable(list< customermodel > data,color bordercolor){
string outputfile = "output.pdf";
string []haeder={"contact","company","city","country","phone"};
pdfdocument pdf = new pdfdocument();
pdfpagebase page = pdf.getpages().add(pdfpagesize.a4, new pdfmargins(40, 30, 40, 30));
pdfborders borders = new pdfborders();
if (bordercolor == null) {
borders.setall(new pdfpen(new pdfrgbcolor(color.translucent)));
} else {
borders.setall(new pdfpen(new pdfrgbcolor(bordercolor)));
}
pdfgrid grid = null;
pdfgridrow pdfgridrow;
pdftruetypefont font1 = new pdftruetypefont(new font("arial", font.bold, 16), true);
pdftruetypefont font2 = new pdftruetypefont(new font("arial", font.plain, 10), true);
pdfstringformat format1 = new pdfstringformat(pdftextalignment.center);
grid = new pdfgrid();
grid.setallowcrosspages(true);
grid.getstyle().setcellspacing(3f);
grid.getcolumns().add(5);
double width = page.getcanvas().getclientsize().getwidth() - (grid.getcolumns().getcount() 1);
grid.getcolumns().get(0).setwidth(width * 0.2);
grid.getcolumns().get(1).setwidth(width * 0.2);
grid.getcolumns().get(2).setwidth(width * 0.2);
grid.getcolumns().get(3).setwidth(width * 0.2);
grid.getcolumns().get(4).setwidth(width * 0.2);
pdfgridrow = grid.getheaders().add(1)[0];
pdfgridrow.setheight(50);
int i = 0;
//header row
for (i = 0; i < haeder.length; i ) {
pdfgridcell cell = pdfgridrow.getcells().get(i);
cell.setcolumnspan(1);
cell.setvalue(haeder[i]);
cell.setstringformat(format1);
cell.getstyle().setborders(borders);
cell.getstyle().setfont(font1);
}
//data row
for (i = 0; i < data.size(); i ) {
pdfgridrow = grid.getrows().add();
pdfgridrow.setheight(40f);
customermodel model=data.get(i);
string []values={model.getcontact(),model.getcompany(),model.getcity(),model.getcountry(),model.getphone()};
for (int j = 0; j < pdfgridrow.getcells().getcount(); j ) {
pdfgridcell cell = pdfgridrow.getcells().get(j);
cell.setcolumnspan(1);
cell.setvalue(values[j]);
cell.getstyle().setborders(borders);
cell.getstyle().setfont(font2);
cell.setstringformat(format1);
}
}
grid.setrepeatheader(true);
grid.draw(page, new point(0, 0));
pdf.savetofile(outputfile, fileformat.pdf);
pdf.close();
}
}
class customermodel {
private string contact;
private string company;
private string city;
private string country;
private string phone;
public string getcontact() {
return contact;
}
public void setcontact(string contact) {
this.contact = contact;
}
public string getcompany() {
return company;
}
public void setcompany(string company) {
this.company = company;
}
public string getcity() {
return city;
}
public void setcity(string city) {
this.city = city;
}
public string getcountry() {
return country;
}
public void setcountry(string country) {
this.country = country;
}
public string getphone() {
return phone;
}
public void setphone(string phone) {
this.phone = phone;
}
}
tab 3
using spire.pdf;
using spire.pdf.graphics;
using spire.pdf.grid;
using system;
using system.collections.generic;
using system.drawing;
namespace demoonlinecode
{
class createtabledemo
{
public void createtable(list< customermodel > data, color bordercolor)
{
string outputfile = "output.pdf";
string[] haeder = { "contact", "company", "city", "country", "phone" };
pdfdocument pdf = new pdfdocument();
pdfpagebase page = pdf.pages.add(pdfpagesize.a4, new pdfmargins(40, 30, 40, 30));
pdfborders borders = new pdfborders();
if (bordercolor == null)
{
borders.all=new pdfpen(new pdfrgbcolor(color.transparent));
}
else
{
borders.all=new pdfpen(new pdfrgbcolor(bordercolor));
}
pdfgrid grid = null;
pdfgridrow pdfgridrow;
pdftruetypefont font1 = new pdftruetypefont(new font("arial",16f, fontstyle.bold), true);
pdftruetypefont font2 = new pdftruetypefont(new font("arial", 10f,fontstyle.regular), true);
pdfstringformat format1 = new pdfstringformat(pdftextalignment.center);
grid = new pdfgrid();
grid.allowcrosspages=true;
grid.style.cellspacing=3f;
grid.columns.add(5);
float width = page.canvas.clientsize.width - (grid.columns.count 1);
grid.columns[0].width=width * 0.2f;
grid.columns[1].width=width * 0.2f;
grid.columns[2].width=width * 0.2f;
grid.columns[3].width=width * 0.2f;
grid.columns[4].width=width * 0.2f;
pdfgridrow = grid.headers.add(1)[0];
pdfgridrow.height=50;
int i = 0;
//header row
for (i = 0; i < haeder.length; i )
{
pdfgridcell cell = pdfgridrow.cells[i];
cell.columnspan=1;
cell.value = haeder[i];
cell.stringformat = format1;
cell.style.borders = borders;
cell.style.font = font1;
}
//data row
for (i = 0; i < data.count; i )
{
pdfgridrow = grid.rows.add();
pdfgridrow.height = 40f;
customermodel model = data[i];
string[] values = { model.contact, model.company,model.city, model.country, model.phone };
for (int j = 0; j < pdfgridrow.cells.count; j )
{
pdfgridcell cell = pdfgridrow.cells[j];
cell.columnspan=1;
cell.value = values[j];
cell.style.borders = borders;
cell.style.font = font2;
cell.stringformat = format1;
}
}
grid.repeatheader = true;
grid.draw(page, new point(0, 0));
pdf.savetofile(outputfile, fileformat.pdf);
pdf.close();
}
}
}
class customermodel
{
public string contact;
public string company;
public string city;
public string country;
public string phone;
}