生成pdf格式报表

  真实惨!集子中了毒,病毒猛于虎啊,还好给清理干净了!  趁着闲暇来的机会,把自动生成报表做完了,终于可以给朋友交差了。

  关于web环境下生成pdf格式的报表有很多解决方案,freereport,jasperreport,fop等等,我这里呢是把原来用servlet写的集成fop程序,放到struts框架里! 

中文测试

又到了工作日,时间变得紧了起来,晚上终于抽出了些时间,完成这个struts程序的测试工作,

既然一起都ok了,大就打开web服务器吧,呵呵  如我所料,尽管在技术路线阶段,已经独立测试了!

STRUTs下还是会出错!找不见路径,访问被拒绝!!呵呵,我想改写一大堆,println()的时候了,尽管

你可以采用apache的log包,可是我还是习惯于这古老的方法!哦! 看问题出来了问题出自

文件名方法用错,改正execute()方法:

                         FormFile file = fileloadForm.getFile();

      String fname=file.getFileName();

现在在运行,一切ok! 

如果你在运行这些代码!请记住,在数据库里建立相应的test表!且各列属性和xls文件对应!

看看我们的测试数据!test.xls

主叫 被叫 通话类型 时长 次数 费率 费用 入中继 时间

85752500 88559318 TH003 27 1 0.1 0.1 65535 20040930145557

85752500 88559318 TH003 141 3 0.1 0.3 65535 20040930145207

85752500 83214163 TH003 12 1 0.1 0.1 65535 20040930134052

85752500 83130000 TH003 42 1 0.1 0.1 65535 20040930112756

85752500 13152046566 TH011 30 1 0 0 65535 20040930112940

85752500 013892428846 TH001 48 1 0.3 0.3 65535 20040930112632

85752500 013891019821 TH001 40 1 0.3 0.3 65535 20040930111452

20040930114350 20040930114350 20040930114350 20040930114350 20040930114350 20040930114350 20040930114350 20040930114350 20040930114350

85752500 06632226858 TH001 23 1 0.3 0.3 65535 20040929172140

数据默认时会从第二行读起

一切噢可了吗?  显然没有  别指望只有英文字母和数字的文件就是工作的结束! 还要做什么? 验证中文!

好  先把名称改了,test.xsl  ==>  中文.xsl  一切ok!(我们好像忘了一件事,一直都没有累加id,显然id,是自动加上的

,所以在没有关注这问题前,不得不删除表格里的书据,为了下一次录入)!

呵呵在实施改一下数据

主叫 被叫 通话类型 时长 次数 费率 费用 入中继 时间

85752500 88559318 TH003 27 1 0.1 0.1 65535 20040930145557

85752500 88559318 限额是 141 3 0.1 0.3 65535 20040930145207

85752500 83214163 测试1 12 1 0.1 0.1 65535 20040930134052

85752500 83130000 TH003 42 1 0.1 0.1 65535 20040930112756

85752500 13152046566 TH011 30 1 0 0 65535 20040930112940

85752500 013892428846 TH001 48 1 0.3 0.3 65535 20040930112632

看的到数据中出现了两窜中文!  在运行! 呵呵  god 终于不愿站在我这边了,埃!  数据库了的中文数据变成了问号!  呵呵  怎么办!  用各简单的方法吧! 把我们的数据成数据库存储的编码方式!

   现在改改我们的read()方法!

    case HSSFCell.CELL_TYPE_STRING :

type = "STRING";

valuestr=cell.getStringCellValue();

//valuestr=new String(newstr.getBytes("GB2312"),"UTF-8");

  try{

valuestr=new String(valuestr.getBytes("GB2312"),"ISO8859_1");

                                     }

                                      catch(Exception e){}

break;

呵呵  看的到就添加了一句,在运行实施,当然一切噢可了!!!

呵呵   可以睡觉去了!

action 与form

阿! 终于写完了action ,看起来并没有什么新的东西可以拿来展览,呵呵  您列代码如下

 STRUTS ACTION

// Created by Xslt generator for Eclipse.

// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))

// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.phone.struts.action;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import java.io.InputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.io.FileOutputStream;

import java.io.File;

import java.sql.*;

import javax.sql.*;

import com.phone.struts.form.FileloadForm;

import org.apache.struts.upload.FormFile;

import com.phone.struts.javabean.excelReadBean;

/**

 * FileloadAction.java created by EasyStruts - XsltGen.

 * http://easystruts.sf.net

 * created on 11-21-2004

 *

 * XDoclet definition:

 * @struts:action path="/fileload" name="fileloadForm" input="/form/fileload.jsp" validate="true"

 * @struts:action-forward name="success.jsp" path="success.jsp"

 * @struts:action-forward name="fail.jsp" path="fail.jsp"

 */

public class FileloadAction extends Action {

// --------------------------------------------------------- Instance Variables

private String fodler=null;

// --------------------------------------------------------- Methods

/**

* Method execute

* @param ActionMapping mapping

* @param ActionForm form

* @param HttpServletRequest request

* @param HttpServletResponse response

* @return ActionForward

* @throws Exception

*/

public ActionForward execute(

ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws Exception {

//Start from here  

 

  Connection conn = null;

      FileloadForm fileloadForm = (FileloadForm) form;

      String fname=fileloadForm.getFileName();

      if(!uploadFile( mapping,  form, request,response))

      {

      System.out.println("upload file failed");

      return mapping.findForward("fail");

      }

      System.out.println("file upload successful");

      excelReadBean readBean=new excelReadBean();

      DataSource dataSource = (DataSource)servlet.getServletContext().getAttribute(

  "org.apache.struts.action.DATA_SOURCE");

  conn = dataSource.getConnection();

readBean.read("test",fodler + "/"+fname,conn);

return mapping.findForward("success");

}

/***

* this function is used to upload file

* @param mapping

* @param form

* @param request

* @param response

*/

public boolean uploadFile(ActionMapping mapping, ActionForm form,

   HttpServletRequest request,

   HttpServletResponse response)

{     

FileloadForm hff = (FileloadForm) form;

if(fodler == null)

  {

  ActionForward test = (ActionForward)mapping.findForward("pathFile");

  fodler = test.getPath();

  }

  if (fodler == null){

  fodler =this.getServlet().getServletContext().getRealPath("/WEB-INF");

  }

  if (fodler != null){

  fodler = fodler.replace('\\', '/').replace('/', File.separatorChar);

  }

  FormFile file = hff.getFile();

  if (file == null ) {

System.out.println("error : file  is null");

return false;

}

// Get the name and file size

String fname = file.getFileName();

String size = Integer.toString(file.getFileSize()) + " bytes";

try{

InputStream streamIn = file.getInputStream();

OutputStream streamOut=null;

streamOut = new FileOutputStream(fodler + "/"+fname);

  int bytesRead = 0;

  byte[] buffer = new byte[8192];

   while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {

streamOut.write(buffer, 0, bytesRead);

   }

  streamOut.close();

  streamIn.close();

}catch(IOException e)

{

System.out.println("IoException:"+e);

}

// Populate the form bean with the results for display in the View

hff.setFileName(fname);

hff.setFileSize(size);

// Clean up our toys when done playing

file.destroy();

    return true;

}

}

可以看到uploadFile()方法用力完成,将客户端的文件上传到,服务器上,而在我们的,主程序里,我们完成了对他的调用,随后调用readBean.read("test",fodler + "/"+fname,conn);完成将xls文件读入数据库.呵呵,初步的轮廓就如此了,可惜要更实用,你必须靠率很多问题,而在此,我想,做个简单的例子,到不用兴师动众。

STRUTS FORM

// Created by Xslt generator for Eclipse.

// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))

// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.phone.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.upload.FormFile;

import org.apache.struts.action.ActionError;

/**

 * FileloadForm.java created by EasyStruts - XsltGen.

 * http://easystruts.sf.net

 * created on 11-21-2004

 *

 * XDoclet definition:

 * @struts:form name="fileloadForm"

 */

public class FileloadForm extends ActionForm {

// --------------------------------------------------------- Instance Variables

/** fileName property */

private String fileName;

/** file property */

private FormFile file;

/** fileSize property */

private String fileSize;

    private boolean isSave;

// --------------------------------------------------------- Methods

/**

* Method validate

* @param ActionMapping mapping

* @param HttpServletRequest request

* @return ActionErrors

*/

public ActionErrors validate(

ActionMapping mapping,

HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

  if (file == null ) {

errors.add("file", new ActionError("error.file"));

  }

  return errors;

}

/**

* Method reset

* @param ActionMapping mapping

* @param HttpServletRequest request

*/

public void reset(ActionMapping mapping, HttpServletRequest request) {

fileName = "";

file = null;

fileSize = "";

        isSave=false;

}

/**

* Returns the fileName.

* @return String

*/

public String getFileName() {

return fileName;

}

/**

* Set the fileName.

* @param fileName The fileName to set

*/

public void setFileName(String fileName) {

this.fileName = fileName;

}

/**

* Returns the file.

* @return FormFile

*/

public FormFile getFile() {

return file;

}

/**

* Set the file.

* @param file The file to set

*/

public void setFile(FormFile file) {

this.file = file;

}

/**

* Returns the fileSize.

* @return String

*/

public String getFileSize() {

return fileSize;

}

/**

* Set the fileSize.

* @param fileSize The fileSize to set

*/

public void setFileSize(String fileSize) {

this.fileSize = fileSize;

}

/**

* @return

*/

public boolean isSave() {

return isSave;

}

/**

* @param b

*/

public void setSave(boolean b) {

isSave = b;

}

}

感觉的出来,注释竟然比程序还占空间,呵呵 感谢xslt 为我们提供了自动转换的方法, 呵呵虽然我还是懒得完成注释,

好久没有玩xsl了,会不会手生呢?

好了最后就是jsp页面了

 <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<%@ page contentType="text/html; charset=GB2312" %>

<html:html>

<body bottommargin="15" topmargin="15" leftmargin="15" rightmargin="15" marginheight="15" marginwidth="15" bgcolor="white" >

<link rel="stylesheet" type="text/css" media="all" href="<%=request.getContextPath()%>/styles/style.css" />

<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/selectbox.js"></script>

<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/global.js"></script>

<title>文件上传:</title>

</head>

<body bottommargin="15" topmargin="15" leftmargin="15" rightmargin="15" marginheight="15" marginwidth="15" bgcolor="white">

<h1>文件上传:</h1>

<!--

        The most important part is to declare your form's enctype

        to be "multipart/form-data", and to have an html:file

        element that maps to your ActionForm's FormFile property

-->

 <html:form action="//fileload.do" enctype="multipart/form-data" >

   

    <html:file property="file" /><html:errors property="file"/></p>

   

    <html:submit />

    </p>

    </html:form>

<p>

</body>

</html:html>

呵呵,html标签为我们提供了简单方面的操作,可惜很多美化工作,还是得借助css,要知道,我总是很

愤恨它,因为它丑陋的各式,为什么就没fo支持呢?还得用,javascript,我总庆幸我不会写,script,

这样总是让我免予帮别人写页面,可惜也因此我不得不依赖别人,copy它们的js.

好像剩下的工作就剩下,调试了,如果你在看,对你确实如此,可是,我的考虑它的应用环境,呵呵,也学我根本

就不需要上传,假如,再本级工作! 不管怎么说,STRUTS下的开发还是这么的快,真的,以前也会被杂乱的jsp,和

servlet搞得头昏脑胀,呵呵   我想该睡个好觉去了!

struts下开发

休息来一早上,现在来吧poi应用移植到struts下,周末快结束了,我必须迅速了结这个任务

,为了简单开发,我还是用eclipse2.1+easy struts ,恩如果你正在我的日记,(实际上,我倒是一直努力将它写成一个给初学者的实例教程)并对easy struts插件不是很了解,你应该先看看"使用 Easy Struts for Eclipse 开发 Struts "这篇文章(在网站内我已经给过它的连接),现在我的各种插件已经配置完成,  开始开发吧!!

 1 ,创建一个tomcat应用,并添加easy struts 支持,看过文章后 这很使简单。

 2 ,创建一个fileuploadfom  and fileuploadbean   ,还是很简单,唯一要提及的form 属性:

     FormFile file;   String fileName; String size;   恩如果你在提示里找不到FormFile 这个类请在类型里键入

     org.apache.struts.upload.FormFile 他关联的html标签相应的是html:file;接着你应该修改一下,formbean

     的reset函数,

  3,恩,还需要给函数加上验证,加入一下代码!同时在propertie 文件中加入error.file 消息

   ActionErrors errors = new ActionErrors();

    if (file == null )

       {

          errors.add("file", new ActionError("error.file")); 

       }

     return errors;

 4, 在我写action志前,我应当将poitest.java 进行修改以适应action的调用,首先在我们的项目文件里加入

    javabean包!现在声成一个javabean excelReadBean,显然它的目的,一眼就可以看出来。

    现在把poitest.java 的read(String table) 方法的代码拷贝过来,恩很显然,少了全局变量:xlsfile(参照原     代码);这里不得不注意这样的问题,为了满足,线程无关性,将read方法变为,read(String table,String xlsfile);

    现在似乎完成了,然而,我们不准备使用,手动连接,为了更方便以后更改,现在来吧数据源放在struts的配置文件里,(参照"使用 Easy Struts for Eclipse 开发 Struts ",现在来完成 DATABASE配置)

  5,既然,要通过Struts框架连接数据库,我想我们的代码也应改修改一下,不过我总是期望以后再次使用这个类,也许并不在Struts框架下,所以我决定使用夺态,在建一个read方法(懒家伙总是向我这样)。

   public boolean read(String table,String xslfile,Connection conn)

{

return false;

} // 为此又不得不引进,sql包,

   现在有理由相信,里面很简单,我们要做的仅仅是将同明方法的代码拷过来!然后删除,曾在上文提及的Rs方法,因为我们用不着他了,加入一下代码:

   Statement stmt = null;

   boolean   rs= false;

  然后将,rs.execute(sql.toString())替换为

  stmt=conn.createStatement();rs=stmt.execute(sql.toString()); 最后return rs;  好一切噢可!如果不想再改观这个类,我想这份工作已经完成了,可是我还是一个类200多行的代码,就是冗余阿,还是修改修改 恩,把读和写剥离开,就这枚简单!  现在来看看修改了后的javabean,  代码又和以前差不多了,呵呵,功能却没有减

/*

 * Created on 2004-11-21

 *

 * To change the template for this generated file go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

package com.phone.struts.javabean;

 

import java.io.*;

import java.util.*;

import javax.sql.*;

import java.sql.*;

import org.apache.poi.hssf.usermodel.*;

import org.apache.poi.hssf.model.*;

import org.apache.poi.poifs.filesystem.*;

import com.cims.db.*;

/**

 * @author Administrator

 *

 * To change the template for this generated type comment go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

public class excelReadBean {

public excelReadBean()

{

}

/**

*

* @param table  this is the name of table in databse

* @param xslfile the excel file which you want to deel with

* @return

*/

public boolean read(String table,String xslfile)

{  

boolean   rs= false;

   rs=read(table,xslfile,null);

return rs;

}

/**

*

* @param table

* @param xslfile

* @param conn

* @return

*/

public boolean read(String table,String xslfile,Connection conn)

{

//@rs for the the result of executing sql

boolean   rs= false;

//construts a poifile

POIFSFileSystem fs=null;

HSSFWorkbook   wb=null; 

try

{

fs =new POIFSFileSystem(new FileInputStream(xslfile));

wb= new HSSFWorkbook(fs);

}catch(IOException e)

{

System.out.println("io exception :"+e);

}

HSSFSheet sheet = wb.getSheetAt(0);

//

System.out.println("the sheet name of  poifile="+wb.getSheetName(0));

int rownum=sheet.getPhysicalNumberOfRows();

System.out.println("the physical Number of rows="+rownum);

for(int rowflag=1;rowflag<rownum;rowflag++)

{

      //enter into row loop

      HSSFRow row = sheet.getRow(rowflag);

      int cells = row.getPhysicalNumberOfCells();

      System.out.println("the total number of cell in this row"+cells);

      System.out.println("this ROW= " + row.getRowNum());

            

      //

      String cellV[]=new String[cells];

      for(int cellflag=0;cellflag<cells;cellflag++)

  {

         //enter into cell loop

                 

         HSSFCell  cell= row.getCell((short)cellflag);

         double    valuenum = 0;

         String    valuestr=null;

         String    type=null;

// i got the code below from org.apache.poi.hssf.dev.hssf class

// and modify some

switch (cell.getCellType())

{

                             case HSSFCell.CELL_TYPE_FORMULA :

      type = "FORMULA ";

      valuestr="null";

  break;

case HSSFCell.CELL_TYPE_NUMERIC :

type = "NUMERIC";

valuenum=cell.getNumericCellValue();

break;

case HSSFCell.CELL_TYPE_STRING :

type = "STRING";

valuestr=cell.getStringCellValue();

break;

   default :

type=null;

}

if(type!=null)

{

System.out.print("the type of this cell is==="+type);

if(valuestr!=null)

{

cellV[cellflag]=valuestr.trim();

System.out.println("the value of this cell is==="+valuestr);

  } else  

  {

  cellV[cellflag]=Double.toString(valuenum);

  System.out.println("the value of this cell is==="+valuenum);

  }

} else

{

  cellV[cellflag]="null";

  System.out.println("erro in the file ,there is a null type cell :"+cellflag);

}

  }

  //here i will manipulate the 'insert' directive of database

  StringBuffer sql=new StringBuffer("insert into "+table+"  values (");

  for(int j=1;j<cells;j++)

  {

sql.append("'"+cellV[j-1]+"',");

  }

  sql.append("'"+cellV[cells-1]+"','"+rowflag+"')");

  System.out.println("sql  "+"="+sql.toString());

//call the write() function

      if(conn!=null)

  {

       rs=this.write(conn,sql.toString());

  }else

        rs=this.write(sql.toString());

     

}

return rs;

}

/**

*

* @param conn  the jdbc connection

* @param sql   the sentence of sql

* @return

*/

private boolean write(Connection conn,String sql)

{

Statement stmt = null;

boolean   rs= false;

try{ 

System.out.println("Start connet to db");

             stmt=conn.createStatement();

         rs=stmt.execute(sql.toString());

        }catch(Exception e)

        {

                 System.out.println("  sql exception "+e);

        }

return rs;

}

/**

*

* @param sql

* @return

*/

private boolean write(String sql)

    {

Rs  resultset=new Rs();

    boolean   rs= false;

    try



   System.out.println("Start connet to db");

           rs=resultset.execute(sql.toString());

}catch(Exception e)

    {

System.out.println("  sql exception "+e);

}

return rs;

}

}

写数据库

晚饭过后,终于有了点精神,顺便把写数据库给做了,这么小的程序就用jdbc吧! 呵呵省力!!!

首先引进import com.cims.db.*;包,其中封装了两个类,conn(创立连接),rs(执行sql)

呵呵接着在 row 循环里续代码了

  /**

   *  below i will connection the database and execute the sql .

              **/

              try

              { 

                    System.out.println("Start connet to db");

                   

                   

                   

                    resultset.execute(sql.toString());

              }catch(Exception e)

              {

                   

                    System.out.println("  sql exception "+e);

              }

就这几行了,所有的数据库操作已经简单封装在被引用的包里。 呵呵  如果您在看我的日记 不是很名白com.cims.db.*

拿酒来看看它中的代码吧!

  conn:  一个创立连接的类  它提供了getConnection方法返回一个connection

  public Connection getConnection() throws SQLException,IOException

{  

String url=null;

String username=null;

    String password=null;

   Connection conn=null;

   Properties props=new Properties();  

   InputStream in = getClass().getResourceAsStream("/database.properties");

   props.load(in);

   System.out.println("hello2");

   in.close();    

    try{

String drivers=props.getProperty("jdbc.drivers");

System.out.println(drivers);

if (drivers!=null)

    Class.forName(drivers).newInstance();

    System.out.println("test for url");

url=props.getProperty("jdbc.url");

System.out.println(url);

username=props.getProperty("username");

password=props.getProperty("password");

System.out.println(password);

   }

   catch(Exception e){System.out.println(e.getMessage());}

   return DriverManager.getConnection(url,username,password);

}

   Rs :sql执行类 其中

      public ResultSet executeQuery(String sql) throws SQLException,IOException方法用于

     数据库查询

      public int executeUpdate(String sql) throws SQLException,IOException 用于数据更新

     当然,还用更通用的方法

     public boolean execute (String sql) throws SQLException,IOException 让他来完成我们的

    数据插入

   看看conn 你就会发现使用jdbc怎么配置数据源了 呵呵  来看看MySQL数据库下配置数据源 

   database.properties的代码:

     jdbc.drivers=org.gjt.mm.mysql.Driver

     jdbc.url=jdbc:mysql://localhost:3306/crm

     username=root

     password=cimserp

  如果你使用的是oracle, 拿酒看看下面例子

    jdbc.drivers=oracle.jdbc.driver.OracleDriver

    jdbc.url=jdbc:oracle:thin:@10.11.12.46:1521:cimserp

    username=cimserp

    password=cimserp

  好了轻轻松松的就将excel中的数据插入数据库了,poi的测试也就到此结束!!我也可以给我朋友说,no problem,

  你需要的很快竟能完成,:)

  看看还需要足作些什么  哦!!  后面几天将把它移植到struts框架下,将用eclipse 2.1 版本+easystruts 快速开发 

    

print 内容

恩,我想应该是print excel 文件的内容的时候了!在read()方法中加入一下代码,并且给read()添加一个参数string tabe  print处所有的sql语句来

for(int rowflag=0;rowflag<rownum;rowflag++)

        {

        //enter into row loop

             HSSFRow row = sheet.getRow(rowflag);

             int cells = row.getPhysicalNumberOfCells();

             System.out.println("the total number of cell in this row"+cells);

             System.out.println("this ROW= " + row.getRowNum());

            

             //

             String cellV[]=new String[cells];

             for(int cellflag=0;cellflag<cells;cellflag++)

             {

             //enter into cell loop

                 

                HSSFCell  cell= row.getCell((short)cellflag);

                double    valuenum = 0;

                String    valuestr=null;

                String    type=null;

                // i got the code below from org.apache.poi.hssf.dev.hssf class

                // and modify some

                switch (cell.getCellType())

                {

                                case HSSFCell.CELL_TYPE_FORMULA :

                                    type = "FORMULA ";

                                    valuestr="null";

                                    break;

                                case HSSFCell.CELL_TYPE_NUMERIC :

                                    type = "NUMERIC";

                                     valuenum=cell.getNumericCellValue();

                                    break;

                                case HSSFCell.CELL_TYPE_STRING :

                                    type = "STRING";

                                    valuestr=cell.getStringCellValue();

                                    break;

                                default :

                                    type=null;

                 }

                 if(type!=null)

                 {

                    System.out.print("the type of this cell is==="+type);

                    if(valuestr!=null)

                    {

                      cellV[cellflag]=valuestr.trim();

                      System.out.println("the value of this cell is==="+valuestr);

                    }

                    else  

                    {

                      cellV[cellflag]=Double.toString(valuenum);

                      System.out.println("the value of this cell is==="+valuenum);

                    }

                 }

                 else

                 {

                      cellV[cellflag]="null";

                      System.out.println("erro in the file ,there is a null type cell :"+cellflag);

                 }

              }

              //here i will manipulate the 'insert' directive of database

              StringBuffer sql=new StringBuffer("insert into "+table+"  values (");

              for(int j=1;j<cells;j++)

              {

                   sql.append("'"+cellV[j-1]+"',");

             }

                      sql.append("'"+cellV[cells-1]+"')");

                      System.out.println("sql  "+"="+sql.toString());

             

             

        }

恩看来excel支持的数据类型有限,它支持四种,FORMULA ,NUMERIC,STRING,date。  我们只用到了三种,很显然我常常会在粘切时莫名其妙的在excel插入空列,很讨厌阿,还是加上type验证吧!

应用poi

   最近答应帮友人完成一微型应用软件,主要功能将xsl数据倒入数据库,并实现报表打印。

   在数据倒入功能上决定采用poi开源项目的hssp子项目,通过hssp类读取xsl数据,并存入数据库库中。

   计划2~7天时间完成poi的学习及应用。

   特立此目标以作记录!