那么,你的修養就會如天地般博大
如果在眾人六神無主之時,你能鎮定自如而不是人云亦云;
如果被眾人猜忌懷疑時,你能自信如常而不去妄加辯論;
如果你有夢想,又能不迷失自我;
如果你有神思,又不至于走火入魔;
如果在成功之中能不忘形于色,而在災難之后也勇于咀嚼苦果;
如果看到自己追求的美好破滅為一堆零碎的瓦礫,也不說放棄;
如果你辛苦勞作,已是功成名就,為了新目標你依舊冒險一搏,哪怕名成為烏有;
如果你跟村夫交流而不變謙恭之態,和王侯散步而不露獻媚之顏;
如果他人的愛情左右不了你,如果你與任何人為伍都能卓然獨立;
如果昏惑的騷擾動搖不了你的意志,你能等自己平心靜氣,再作答時;
那么,你的修養就會如天地般博大,而你就是個真正的 男子漢.
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);
?}
}