那么,你的修养就会如天地般博大
如果在众人六神无主之时,你能镇定自如而不是人云亦云;
如果被众人猜忌怀疑时,你能自信如常而不去妄加辩论;
如果你有梦想,又能不迷失自我;
如果你有神思,又不至于走火入魔;
如果在成功之中能不忘形于色,而在灾难之后也勇于咀嚼苦果;
如果看到自己追求的美好破灭为一堆零碎的瓦砾,也不说放弃;
如果你辛苦劳作,已是功成名就,为了新目标你依旧冒险一搏,哪怕名成为乌有;
如果你跟村夫交流而不变谦恭之态,和王侯散步而不露献媚之颜;
如果他人的爱情左右不了你,如果你与任何人为伍都能卓然独立;
如果昏惑的骚扰动摇不了你的意志,你能等自己平心静气,再作答时;
那么,你的修养就会如天地般博大,而你就是个真正的 男子汉.
public class TestPoi extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
File file = new File("D:\\b.doc");
try
{
FileInputStream in = new FileInputStream("D:\\b.doc");
// HWPFFileSystem hwpfsys = new HWPFFileSystem();
// hwpfsys.getStream("d://b.doc");
POIFSFileSystem pfs = new POIFSFileSystem(in);
HWPFDocument hwpf = new HWPFDocument(pfs);
// hwpf.write(hwpfsys.getStream("D://e.doc"));
// Range range = new Range(0, (int) file.length(), hwpf);
Range range = hwpf.getRange();
StyleSheet styleSheet = hwpf.getStyleSheet();
TableIterator it = new TableIterator(range);
//遍历一个DOC中的所有表格
while (it.hasNext())
{
Table tb = (Table) it.next();
//遍历表格的行
for (int i = 0; i < tb.numRows(); i++)
{
TableRow tr = tb.getRow(i);
//遍历表格的列
for (int j = 0; j < tr.numCells(); j++)
{
//往表格中插入数据
TableCell td = tr.getCell(j);
String text = "第" + i + "行第" + j + "列";
int p = td.numParagraphs();
Paragraph para = td.getParagraph(p);
ParagraphProperties pp = new ParagraphProperties();
para.insertBefore(text);
}
}
}
//在表格外面插入内容
CharacterProperties cp = new CharacterProperties();
cp.setBold(true);
cp.setCharacterSpacing(10);
cp.setChse(cp.SPRM_CHARSCALE);
cp.setCapitalized(true);
int p = range.numParagraphs();
Paragraph para = range.getParagraph(p - 1);
para.insertAfter("test poi successful!", cp);
para.insertAfter("测试成功", cp);
response.setContentType("application/vnd.ms-word");
response.setHeader("Content-disposition", "attachment;filename=e.doc");
OutputStream out = response.getOutputStream();
hwpf.write(out);
out.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
doGet(request, response);
}
}