怎用用java导入、导入word形式的考试题目? 5

 我来答
云来别有山高4
推荐于2016-02-16 · TA获得超过1.1万个赞
知道小有建树答主
回答量:1100
采纳率:100%
帮助的人:339万
展开全部
使用java中的io进行读取
BufferedReader bufferedReader = null;

File file = new File("文档地址+文档名.docx");
if(!file.exists()){
System.out.println("文件不存在");
} else {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "读取的字符格式(UTF-8或GBK)"));
String lineText = null;
while((lineText = bufferedReader.readLine()) != null){
if (linText != null && !lineText.eq("")){
System.out.println("一次读取一行,一行内容为:" + lineText);
百度网友02f511ee1
2012-07-10
知道答主
回答量:33
采纳率:0%
帮助的人:13.4万
展开全部
顶楼上
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xidianheyanjun
2012-07-06 · TA获得超过296个赞
知道小有建树答主
回答量:598
采纳率:0%
帮助的人:431万
展开全部
你好
可以试试POI
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
dngoryaner
2012-07-04 · TA获得超过2350个赞
知道小有建树答主
回答量:2404
采纳率:0%
帮助的人:1229万
展开全部
/**
* 创建word文档 步骤: 1,建立文档 2,创建一个书写器 3,打开文档 4,向文档中写入数据 5,关闭文档
*/
public class WordDemo {
public WordDemo() {
}
COS_MANIFEST_DTLS
/**
* @param args
*/
public static void main(String[] args) {
// 创建word文档,并设置纸张的大小
Document document = new Document(PageSize.A4);
try {
RtfWriter2.getInstance(document,
new FileOutputStream("E:/word.doc"));

document.open();

//设置合同头

Paragraph ph = new Paragraph();
Font f = new Font();

Paragraph p = new Paragraph("出口合同",
new Font(Font.NORMAL, 18, Font.BOLDITALIC, new Color(0, 0, 0)) );
p.setAlignment(1);
document.add(p);
ph.setFont(f);

// 设置中文字体
// BaseFont bfFont =
// BaseFont.createFont("STSongStd-Light",
"UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
// Font chinaFont = new Font();
/*
* 创建有三列的表格
*/
Table table = new Table(4);
document.add(new Paragraph("生成表格"));
table.setBorderWidth(1);
table.setBorderColor(Color.BLACK);
table.setPadding(0);
table.setSpacing(0);

/*
* 添加表头的元素
*/
Cell cell = new Cell("表头");//单元格
cell.setHeader(true);
cell.setColspan(3);//设置表格为三列
cell.setRowspan(3);//设置表格为三行
table.addCell(cell);
table.endHeaders();// 表头结束

// 表格的主体
cell = new Cell("Example cell 2");
cell.setRowspan(2);//当前单元格占两行,纵向跨度
table.addCell(cell);
table.addCell("1,1");
table.addCell("1,2");
table.addCell("1,3");
table.addCell("1,4");
table.addCell("1,5");
table.addCell(new Paragraph("用java生成的表格1"));
table.addCell(new Paragraph("用java生成的表格2"));
table.addCell(new Paragraph("用java生成的表格3"));
table.addCell(new Paragraph("用java生成的表格4"));
document.add(new Paragraph("用java生成word文件"));
document.add(table);
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 3条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式