java代码插入wps java读取wps建的excel( 三 )


// 设置excel标题
//cellFormat.setBackground(Colour.AQUA);
cellFormat.setFont(wfont);
label.setCellFormat(cellFormat);
wsheet.addCell(label);
//wsheet.addCell(new Label(0, 0, tmptitle, wcfFC));
wsheet.setRowView(0,500); //第一行高度
wsheet.mergeCells(0, 0, 6, 1);//合并单元格(第一列的第一行和第七列的第二行合并)
//wsheet.mergeCells(0, 1, 9, 1);
//wsheet.mergeCells(0, 2, 0, 4);
//wsheet.mergeCells(1, 2, 3, 2);
//wsheet.mergeCells(4, 2, 6, 2);
//wsheet.mergeCells(7, 2, 9, 2);
wsheet.setColumnView(0,10); //宽度
wsheet.setColumnView(1,25); //宽度
wsheet.setColumnView(2,10); //宽度
wsheet.setColumnView(3,10); //宽度
wsheet.setColumnView(4,10); //宽度
wsheet.setColumnView(5,10); //宽度
// 开始生成主体内容
wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 14,WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
wcfFC = new WritableCellFormat(wfont);
wsheet.addCell(new Label(0, 2, "名次",wcfFC));
wsheet.addCell(new Label(1, 2, "驾校名称",wcfFC));
wsheet.addCell(new Label(2, 2, "科目一",wcfFC));
wsheet.addCell(new Label(3, 2, "科目二",wcfFC));
wsheet.addCell(new Label(4, 2, "科目三",wcfFC));
wsheet.addCell(new Label(5, 2, "合格率",wcfFC));
int count=jxhelpmList.size();
if(count0){////判断集合是否不为0
TjJxkshgl tjhgl=null;
for(int i=0;ijxhelpmList.size();i++){
tjhgl=(TjJxkshgl)jxhelpmList.get(i);
wsheet.addCell(new Label(0, i+3, (i+1)+""));
wsheet.addCell(new Label(1, i+3, tjhgl.getJxmc()));
wsheet.addCell(new Label(2, i+3, tjhgl.getKm1hgl()));
wsheet.addCell(new Label(3, i+3, tjhgl.getKm2hgl()));
wsheet.addCell(new Label(4, i+3, tjhgl.getKm3hgl()));
wsheet.addCell(new Label(5, i+3, tjhgl.getAvghgl()));
}
您好 , 我想用java代码调用wps?代码方法如下java代码插入wps,从流加载wps文件java代码插入wps,转为pdf格式
import com.spire.doc.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class WordToPDF {
public static void main(String[] args)throws IOException {
FileInputStream inputStream = new FileInputStream(new File("test.wps"));
Document document = new Document();
document.loadFromStream(inputStream, FileFormat.Doc);
document.saveToFile("WPStoPDF.pdf",FileFormat.PDF);
}
}
在程序中需引入 spire.doc.jar 。
能写个读取.wps后缀名文档的Java程序吗?如下方法,代码思路:加载一个.wps格式的文档 , 获取文档中的文本或图片,将获取到的内容保存到本地路径 。下面以分别读取文本和图片为例:
1.读取WPS中的文本
import com.spire.doc.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
public class ReadTextFromWPS {
public static void main(String[] args) throws IOException{
//通过流加载WPS文字文档
FileInputStream inputStream = new FileInputStream(new File("test.wps"));
Document doc = new Document();
doc.loadFromStream(inputStream, FileFormat.Doc);
//获取文本保存为String
String text = doc.getText();
//将String写入Txt
writeStringToTxt(text,"读取WPS文本.txt");
}
public static void writeStringToTxt(String content, String txtFileName) throws IOException {
FileWriter fWriter= new FileWriter(txtFileName,true);
try {
fWriter.write(content);
}catch(IOException ex){
ex.printStackTrace();
}finally{
try{
fWriter.flush();
fWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
2.读取WPS中的图片

推荐阅读