JAVA的B/S架构的Word导入、导出功能,Word模板有较复
杂的表格,导入时需要从表格中取数据写到数据库表,
导出时需要把数据填写到Word模板的表格中。
请高手指点迷津,help!!不胜感激...

解决方案 »

  1.   

    word的话,可以用JACOM....楼主可以去google一下
      

  2.   

    谢谢2楼的帮助,正在google中~~~
      

  3.   


    楼主,关于word的话其实是有很多种方法可以读写的!!比如itext,poi等等
    我以前就用过itext来产生word文档。。
    发个小例子你自己看看把!!package com.wepull.zct;import com.lowagie.text.Cell;
    import com.lowagie.text.Document;  
    import com.lowagie.text.DocumentException;  
    import com.lowagie.text.Element;
    import com.lowagie.text.Font;  
    import com.lowagie.text.Image;  
    import com.lowagie.text.PageSize;  
    import com.lowagie.text.Paragraph;
    import com.lowagie.text.Table;
    import com.lowagie.text.pdf.BaseFont;  
    import com.lowagie.text.rtf.RtfWriter2;  import java.awt.Color;
    import java.io.FileNotFoundException;  
    import java.io.FileOutputStream;  
    import java.io.IOException;  
    import com.lowagie.text.rtf.style.RtfParagraphStyle; 
    public class RTFCreate2 { private static final String FILE_NAME = "D:/JAVA第一个RTF文档生成.doc";       
        public static void main(String[] args) {   
          
          
        try {   
          
        RTFCreate2 rtfMain = new RTFCreate2();   
          
        rtfMain.createRTFContext(FILE_NAME);   
          
          
          
          
        } catch (FileNotFoundException e) {   
          
          
        e.printStackTrace();   
          
        } catch (DocumentException e) {   
          
          
        e.printStackTrace();   
          
        } catch (IOException e) {   
        e.printStackTrace();   
          
        }   
          
        }   
          
          
          
          
        public void createRTFContext(String path) throws DocumentException,   
          
        IOException {   
          
        Document document = new Document(PageSize.A4);   
          
        RtfWriter2.getInstance(document, new FileOutputStream(path));   
          
        document.open();   
          
        Paragraph title = new Paragraph("标题");   
        // 设置标题格式对齐方式  
        title.setAlignment(Element.ALIGN_CENTER); 
    //     title.alignment();\
        //标题颜色
        title.font().setColor(Color.red);
        //设置标题样式
        title.font().setStyle(Font.ITALIC);
        //标题大小
        title.font().setSize(24);
        document.add(title);   
        
        
          
          
    //      正文字体风格  
    String contextString = "iText是一个能够快速产生PDF文件的java类库。" +
    "iText的java类对于那些要产生包含文本,表格," +
    "图形的只读文档是很有用的。" +
    "它的类库尤其与java Servlet有很好的给合。" +
    "使用iText与PDF能够使你正确的控制Servlet的输出。";   
          
        Paragraph context = new Paragraph(contextString);   
         
        // 正文格式左对齐  
        
        context.setAlignment(Element.ALIGN_LEFT);   
        context.font().setColor(Color.cyan);  
        context.font().setStyle(Font.HELVETICA);
        context.font().setSize(15);
        //让setFont见鬼去
        //context.setFont(contextFont);   
          
        // 离上一段落(标题)空的行数  
          
        context.setSpacingBefore(20);   
          
        // 设置第一行空的列数  
          
        context.setFirstLineIndent(20);   
          
          
          
          
        document.add(context);   
          
        Table table = new Table(3);  
            int width[] = {25,25,50};//设置每列宽度比例  
            table.setWidths(width);  
            table.setWidth(90);//占页面宽度比例  
            table.setAlignment(Element.ALIGN_CENTER);//居中  
            table.setAlignment(Element.ALIGN_MIDDLE);//垂直居中  
            table.setAutoFillEmptyCells(true);//自动填满  
            table.setBorderWidth(1);//边框宽度  
            //设置表头  
            Cell haderCell = new Cell("表格表头");  
            haderCell.setHeader(true);  
            haderCell.setColspan(3);  
            table.addCell(haderCell);  
            table.endHeaders();  
            Font fontChinese = new Font(Font.NORMAL,12,Font.NORMAL,Color.GREEN);  
            Cell cell = new Cell(new Paragraph("这是一个3*3测试表格数据",fontChinese));  
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            table.addCell(cell);  
            table.addCell(new Cell("#1"));  
            table.addCell(new Cell("#2"));  
            table.addCell(new Cell("#3"));  
              
            document.add(table); 
          
          
        // //在表格末尾添加图片  
          
        Image png = Image.getInstance("Splashbg.png");   
          
        document.add(png);   
          
        document.close();   
          
    }   
    }你可以参照这写,这个需要导入itext的jar包。。我用的是itext-2.0.1.jar这个jar包!!
    其实读跟这个差不多, 你只是需要将相应的方法修改一下即可!!
      

  4.   

    用了SOAOffice中间件,达到了我的效果,正在探索其他方法,谢谢大家的帮助!!