📄 copyeditexcel.java
字号:
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
wc =ws.getWritableCell(11,5);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,this.cellWidth,true);
wc =ws.getWritableCell(12,5);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
wc =ws.getWritableCell(14,5);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
wc =ws.getWritableCell(16,5);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
wc =ws.getWritableCell(14,3);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
wc =ws.getWritableCell(16,4);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
wc =ws.getWritableCell(16,9);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
wc =ws.getWritableCell(16,10);
this.setBorderOK(ws,wf,jxl.format.Alignment.CENTRE,wc.getContents(),true);
//
for (int i = 0, j = 0; i < stand.length; ) {
wc = ws.getWritableCell(stand[i], stand[i + 1]);
this.setWcContent(this.number[j], ws);
i++;
i++;
j++;
}
System.out.println("Page" + this.page + " number OK!");
stand = es.standardName(10);
for (int i = 0, j = 0; i < stand.length; ) {
wc = ws.getWritableCell(stand[i], stand[i + 1]);
this.setWcContent(this.name[j], ws);
i++;
i++;
j++;
}
System.out.println("Page" + this.page + " name OK!");
stand = es.standardValue(10);
for (int i = 0, j = 0; i < stand.length; ) {
wc = ws.getWritableCell(stand[i], stand[i + 1]);
this.setWcContent(this.lon[j], ws);
wc = ws.getWritableCell(stand[i], stand[i + 1] + 1);
this.setWcContent(this.lat[j], ws);
i++;
i++;
j++;
}
wc = ws.getWritableCell(0, 30);
Label l5 = (Label) wc;
l5.setString(" 记录: 复核: " +
"第 " + page + " 页,共 " + this.totalPage + " 页");
System.out.println("Page" + this.page + " lat&lon OK!");
}
catch (Exception e) {
e.printStackTrace();
}
}
private void wwbClose() {
try {
wwb.write();
wwb.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
/*
1、先计算出来分多少页
2、再按照页数,取出第一次4个数组
3、余下的,如果不够的话,补充空字符;如果多余继续重复第2步。
*/
private void fenye(String tracksName,String[] number, String[] name, String[] lat,
String[] lon, int pageReduce) throws Exception{
this.tracksName = tracksName;
//private String[] numberTemp = null, nameTemp = null, latTemp = null, lonTemp=null;
if (pageReduce > 1) { //如果页数不只一个。
for (int i = 0; i < 40; i++) {
this.number[i] = number[i];
this.name[i] = name[i];
this.lat[i] = lat[i];
this.lon[i] = lon[i];
}
//假如是第一次创建的话(用firstPage判断),拷贝原文件
if (firstPage) {
jxl.write.WritableSheet ws = wwb.getSheet(0);
this.createFile(ws);
firstPage = false;
}
else { //假如不是第一次的话,拷贝第一个Sheet
wwb.copySheet(0, "page" + page, page - 1);
jxl.write.WritableSheet ws = wwb.getSheet(page - 1);
this.createFile(ws);
}
this.numberTemp = new String[number.length - 40];
this.nameTemp = new String[name.length - 40];
this.latTemp = new String[lat.length - 40];
this.lonTemp = new String[lon.length - 40];
//
for (int i = 0; i < number.length - 40; i++) {
this.numberTemp[i] = number[i + 40];
this.nameTemp[i] = name[i + 40];
this.latTemp[i] = lat[i + 40];
this.lonTemp[i] = lon[i + 40];
}
page++;
fenye(tracksName,numberTemp, nameTemp, latTemp, lonTemp, pageReduce - 1);
}
else { //如果页数只有一个了。可能有空,也可能刚好。
for (int i = 0; i < 40; i++) {
if (i < number.length) {
this.number[i] = number[i];
this.name[i] = name[i];
this.lat[i] = lat[i];
this.lon[i] = lon[i];
}
else {
this.number[i] = " ";
this.name[i] = " ";
this.lat[i] = "0.0";
this.lon[i] = "0.0";
}
}
//假如是第一次创建的话(用firstPage判断),拷贝原文件
if (firstPage) {
jxl.write.WritableSheet ws = wwb.getSheet(0);
this.createFile(ws);
firstPage = false;
}
else { //假如不是第一次的话,拷贝第一个Sheet
wwb.copySheet(0, "page" + page, page - 1);
jxl.write.WritableSheet ws = wwb.getSheet(page - 1);
this.createFile(ws);
}
this.wwbClose();
}
}
public String setUnderLineOK(String str){
String string ="";
int length =10;
int temp =0;
byte[] b = str.getBytes();
if(b.length<length){
temp = length - b.length;
for(int i=0;i<temp/2;i++){
string = string+" ";
}
string = string +str;
for(int i=0;i<temp/2;i++){
string = string+" ";
}
}else{
string = str;
}
return string;
}
public static void setWaypointIfBeginOfTracks(String waypointName){
waypointOfBegin = waypointName;
}
public static void setWaypointIfEndOfTracks(String waypointName){
waypointOfEnd = waypointName;
}
public static void setDistance(String distance){
disctance = distance;
}
public void fileCreate(String tracksName,String[] number, String[] name, String[] lat,
String[] lon,String cellNumber,String cellName ,String cellType,String cellWidth,String t1,String t2,String t3,String t4,String t5,String t6,String t7) throws Exception{
this.cellNumber =cellNumber;
this.cellName = cellName;
this.cellType = cellType;
this.cellWidth = cellWidth;
this.t1 = setUnderLineOK(t1);
this.t2 = setUnderLineOK(t2);
this.t3 = setUnderLineOK(t3);
this.t4 = setUnderLineOK(t4);
this.t5 = t5;
Date d =null;
if(!(t6.equals(""))){
d = new Date(t6);
//this.t6 = (d.getYear()+1900)+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日";
this.t6 = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG).
format(d);
}
if(!(t7.equals(""))){
d = new Date(t7);
this.t7 = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG).
format(d);
}
ExcelPage ep = new ExcelPage(number);
totalPage = ep.getPage();
fenye(tracksName,number, name, lat, lon, totalPage);
}
public static void main(String args[]) {
/*
String[] number = new String[myTest.lat.size()], name = new String[myTest.lat.size()], lat = new String[myTest.lat.size()], lon = new String[myTest.lat.size()];
for (int i = 0; i < number.length; i++) {
number[i] = "" + (i + 1);
name[i] = "名称" + (i + 1);
lat[i] = myTest.lat.get(i) + "";
lon[i] = myTest.lon.get(i)+"";
}
}
*/
/*/////////////////////////////////////////////////////////////////
CopyEditExcel t = new CopyEditExcel("D:\\GIS\\Excel\\test.xls");
t.fileCreate("",number, name, lat, lon);
////////////////////////////////////////////////////////////////*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -