struts2 导出pdf excel_excel表格怎么导出pdf

2020-02-28 其他范文 下载本文

struts2 导出pdf excel由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“excel表格怎么导出pdf”。

Action 配置: Excelaction :

application/vnd.ms-excel

name=“exportAetRequisitionAction” cla=“com.action.aets.export.ExportAetRequisitionAction” method=“execute”> name=“contentDisposition”>attachment;filename=“${fileName}”

inputStream Pdfaction:

name=“exportAetRequisitionPdfAction” cla=“com.action.aets.export.ExportAetRequisitionPdfAction” method=“execute”>

application/pdf;charset=gb2312

导出pdf:

1.import com.lowagie.text.Document;

2.import com.lowagie.text.Font;

3.import com.lowagie.text.Paragraph;

4.import com.lowagie.text.pdf.BaseFont;

5.import com.lowagie.text.pdf.PdfWriter;

6.private InputStream pdfStream;

7.8./**

9.* 导出PDF 格式 10.* @return

11.*/

public cla ExportAetRequisitionPdfAction extends BaseAction { private static final long serialVersionUID = 1L;private String fileName;

attachment;filename=“${fileName}”

2048

inputStream

private ByteArrayOutputStream buffer;private ByteArrayInputStream inputStream;public ByteArrayOutputStream getBuffer(){ return buffer;} public void setBuffer(ByteArrayOutputStream buffer){ this.buffer = buffer;} public InputStream getInputStream(){ return inputStream;} public String getFileName(){ } return fileName;public void setFileName(String fileName){ this.fileName = fileName;} public String execute()throws Exception{

try{

this.setFileName(“调拨单.pdf”);

fileName = new String(fileName.toString().getBytes(), “ISO8859-1”);

Rectangle rectPageSize = new Rectangle(PageSize.A4);// 定义A4页面大小

rectPageSize = rectPageSize.rotate();// 加上这句可以实现A4页面的横置

// 左 右 上 下

Document document = new Document(rectPageSize, 10, 10, 80, 50);// 其余4个参数,设置了页面的4个边距

BaseFont bfChinese = BaseFont.createFont(“STSong-Light”, “UniGB-UCS2-H”, BaseFont.NOT_EMBEDDED);

Font FontChinese = new Font(bfChinese);

ByteArrayOutputStream buffer = new ByteArrayOutputStream();

PdfWriter.getInstance(document, buffer);

document.open();

document.add(new Paragraph(“中文Hello World”,FontChinese));

document.close();

} catch(Exception e)

{ e.printStackTrace();

}

this.pdfStream = new ByteArrayInputStream(buffer.toByteArray());

buffer.close();

return SUCCESS;

}

}

导出excel:

public cla ExportAetRequisitionAction extends BaseAction { private static final long serialVersionUID = 1L;

private String fileName;private ByteArrayOutputStream baos;private ByteArrayInputStream inputStream;public ByteArrayOutputStream getBaos(){ return baos;} public void setBaos(ByteArrayOutputStream baos){ } this.baos = baos;public ByteArrayInputStream getInputStream(){ return inputStream;} public void setInputStream(ByteArrayInputStream inputStream){ this.inputStream = inputStream;} public String getFileName(){ return fileName;} public void setFileName(String fileName){ this.fileName = fileName;} @SuppreWarnings(“unchecked”)public String execute()throws Exception{

try{

this.setFileName(“调拨单.xls”);

fileName = new String(fileName.toString().getBytes(), “ISO8859-1”);HttpServletRequest request = ServletActionContext.getRequest();request.setCharacterEncoding(“UTF-8”);// 表头字段内容

beg--> List headlist = new ArrayList();headlist.add(“品

名”);

headlist.add(“规

格”);headlist.add(“单位”);headlist.add(“数

量”);

headlist.add(“单

价”);headlist.add(“金

额”);headlist.add(“备

注”);List headlistMoney = new ArrayList();headlistMoney.add(“十”);

}

}

headlistMoney.add(“万”);headlistMoney.add(“千”);headlistMoney.add(“百”);headlistMoney.add(“十”);headlistMoney.add(“元”);headlistMoney.add(“角”);headlistMoney.add(“分”);int[]widths= { 6000,6000,800,3000,3000,600,600,600,600,600,600,600,600,9000};// 表头字段内容

end

HSSFSheet sheet = wb.createSheet(“调拨单”);for(int j=0;j

CreateTableHeader(wb, sheet, headlist, headlistMoney);//创建表头 CreateTableRowLine(wb, aetsInfoList, sheet);//创建表格内容

baos = new ByteArrayOutputStream();baos.flush();wb.write(baos);} catch(Exception e){ e.printStackTrace();} inputStream = new ByteArrayInputStream(baos.toByteArray());return SUCCESS;

《struts2 导出pdf excel.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
struts2 导出pdf  excel
点击下载文档
相关专题 excel表格怎么导出pdf PDF EXCEL excel表格怎么导出pdf PDF EXCEL
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文