itext java word_java 生成简单word(利用Itext工具),生成简单Excel,以及下载笔记...

/*** 新建报告(报告名字。图片。新闻id)

*

*@throwsJSONException*/@OverridepublicString addReport(String[] img, String[] newsId, String reportName, String loginId, String path,

String imgPath) {

Long name=System.currentTimeMillis();

String filePath= path + File.separator + name + ".doc";

File file= newFile(filePath);

Report report= newReport();

report.setLoginId(loginId);

report.setReportName(reportName);

report.setDownUrl(filePath);

fileDao.addReport(report);

System.out.println("插入报告成功" +report.getReportNo());

Document document= newDocument(PageSize.A4);try{

RtfWriter2.getInstance(document,newFileOutputStream(file));

}catch(FileNotFoundException e2) {//TODO Auto-generated catch block

e2.printStackTrace();

}

document.open();

BaseFont bfChinese= null;try{

bfChinese=BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

}catch (DocumentException |IOException e1) {

e1.printStackTrace();

}

Font titleFont= new Font(bfChinese, 22, Font.BOLD);

Font contextFont= new Font(bfChinese, 10, Font.NORMAL);

Paragraph title= new Paragraph("统计报告", titleFont);

title.setAlignment(Element.ALIGN_CENTER);//红色的线

RtfShapePosition position;

position= new RtfShapePosition(150, 0, 10400, 170);

position.setXRelativePos(RtfShapePosition.POSITION_X_RELATIVE_MARGIN);

position.setYRelativePos(RtfShapePosition.POSITION_Y_RELATIVE_PARAGRAPH);

RtfShape shape= newRtfShape(RtfShape.SHAPE_RECTANGLE, position);

RtfShapeProperty property= newRtfShapeProperty(RtfShapeProperty.PROPERTY_LINE_COLOR, Color.RED);

shape.setProperty(property);

Paragraph p1= newParagraph(shape);try{//logo

Image imglogo = Image.getInstance(imgPath + File.separator + "dfgx.jpg");

imglogo.setAlignment(Image.LEFT);//设置图片显示位置

imglogo.scaleAbsolute(80, 50);//直接设定显示尺寸

document.add(imglogo);

document.add(title);

document.add(p1);

}catch(Exception e) {

e.printStackTrace();

}

Table table= null;try{

table= new Table(4);int width[] = { 40, 30, 15, 15 };//设置每列宽度比例

table.setWidths(width);

}catch(Exception e1) {

e1.printStackTrace();

}

table.setBorderWidth(1);

table.setBorderColor(Color.BLACK);

table.setPadding(0);

table.setSpacing(0);try{

table.addCell("标题");

table.addCell("链接");

table.addCell("渠道");

table.addCell("时间");

}catch(BadElementException e1) {

e1.printStackTrace();

}

List list =estoWeb.SelectId(newsId);

String time= "";

String titleinfo= "";

String url= "";

String channel= "";try{for(Object string : list) {

JSONObject json= null;

json= newJSONObject(String.valueOf(string));

channel= (String) json.get("webCell");

titleinfo= (String) json.get("titleCell");

url= (String) json.get("linkCell");

time= (String) json.get("dateCell");

table.addCell(newParagraph(titleinfo));

table.addCell(newParagraph(url));

table.addCell(newParagraph(channel));

table.addCell(newParagraph(time));

}

}catch(Exception e) {

e.printStackTrace();

}try{

document.add(table);

}catch(DocumentException e1) {

e1.printStackTrace();

}for(String string : img) {

Map map =fileDao.findReportPath(string);

System.out.println(map.get("PIC_PATH"));

Image img1= null;try{

img1= Image.getInstance(imgPath + File.separator + String.valueOf(map.get("PIC_PATH")));

}catch(BadElementException e) {

e.printStackTrace();

}catch(MalformedURLException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}

img1.setAbsolutePosition(0, 0);

img1.setAlignment(Image.ALIGN_CENTER);//设置图片显示位置

img1.scaleAbsolute(360, 180);//直接设定显示尺寸

try{

document.add(img1);

}catch(DocumentException e) {

e.printStackTrace();

}

}

document.close();return "ok";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值