我正在使用java2word库从IBM Notes数据库数据生成Word文档。
我的问题是我得到的文档被解释为包含ms单词的错误,只能通过文本恢复。
当我在Word Repair弹出窗口中单击“转到”按钮(一旦我在恢复状态下打开文档后)时,什么也没有发生,并且从对话框中我什么也看不到。 (德语)
我已经在我的Agent类中成功使用了另外2个库,所以我很确定它不能是数据收集和解析到我的Document Writing类。 以下代码成功运行。
用于临时存储数据的DataRow类:
public class DataRow {
String Date;
String VorgangDesc;
String DayShort;
double Hours;
public DataRow(String Dayshort, String Vorgangdesc, double hours, String date1){
Date=date1;
VorgangDesc=Vorgangdesc;
DayShort=Dayshort;
Hours=hours;
}
}
用于实现java2word的BerichtsHeft类:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import lotus.domino.Session;
import word.api.interfaces.IDocument;
import word.api.interfaces.IElement;
import word.utils.TestUtils;
import word.utils.Utils;
import word.w2004.Document2004;
import word.w2004.Document2004.Encoding;
import word.w2004.elements.BreakLine;
import word.w2004.elements.Table;
import word.w2004.elements.tableElements.TableEle;
public class BerichtsHeft {
public String Name;
public String startD;
public Session CurrentS;
public int TableCount=1;
public String Abteilung;
public int AusbildungsJahr;
String[] ItemsLastRow = new String[] {"..." , "...", "..."};
String[] ItemsFirstRow = new String[] {"Ausbildungsnachweis", "Nr." + TableCount, "Woche vom" + startD + "bis" + "e end"};
PrintWriter writer = null;
Table CurrentTable;
IDocument myDoc;
public BerichtsHeft(String strName, String startDate, Session CurrentSes, String abteilung){
this.Name=strName;
this.startD=startDate;
this.CurrentS=CurrentSes;
this.Abteilung=abteilung;
this.myDoc = new Document2004();
myDoc.encoding(Encoding.UTF_8);
}
public void Spacer(){
myDoc.addEle(BreakLine.times(1).create());
}
public void createTable(ArrayList<DataRow> DataList){
Table tbl = new Table();
CurrentTable = tbl;
String[] ItemsFlexible = new String[3];
AddFirstRow(ItemsFirstRow);
for(int ij2=0; ij2<DataList.size(); ij2++){
ItemsFlexible[0]=DataList.get(ij2).DayShort.toString();
ItemsFlexible[1]=DataList.get(ij2).VorgangDesc.toString();
ItemsFlexible[2]=Double.toString(DataList.get(ij2).Hours);
AddRow(ItemsFlexible);
}
AddLastRow(ItemsLastRow);
myDoc.addEle(CurrentTable);
TableCount++;
Spacer();
}
public void AddFirstRow(String[] Items){
CurrentTable.addTableEle(TableEle.TH, Items);
}
public void AddRow(String[] items){
CurrentTable.addTableEle(TableEle.TD, items);
}
public void AddLastRow(String[] items){
CurrentTable.addTableEle(TableEle.TD, items);
}
public void logNext(){
}
public void SaveDoc(){
File fileObj = new File("C:\\temp\\test2.doc");
PrintWriter writer = null;
try {
writer = new PrintWriter(fileObj);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String myWord = myDoc.getContent();
writer.println(myWord);
writer.close();
}
}
Pastebin链接到文本格式的Word文档 PasteBin link to text Word Doc
找到这些错误根源的最佳方法是什么?