/** * @author Ken * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class CreateXLS {
public static void main(String[] args) { try { //open file. WritableWorkbook book = Workbook.createWorkbook(new File("d:/Test.xls"));
//create Sheet named "Sheet_1". 0 means this is 1st page. WritableSheet sheet = book.createSheet("Sheet_1", 0);
//define cell column and row in Label Constructor, and cell content write "test". //cell is 1st-Column,1st-Row. value is "test". Label label = new Label(0, 0, "test"); //add defined cell above to sheet instance. sheet.addCell(label);
//create cell using add numeric. WARN:necessarily use integrated package-path, otherwise will be throws path-error. //cell is 2nd-Column, 1st-Row. value is 789.123. jxl.write.Number number = new jxl.write.Number(1, 0, 789.123); //add defined cell above to sheet instance. sheet.addCell(number);
//add defined all cell above to case. book.write(); //close file case. book.close(); } catch (Exception e) { e.printStackTrace(); } } }
还有个问题,我访问ORACLE,用的PROC*C,但发觉不够灵活,因为表很多,而每个表的列数又不一样,这样的话为取出所有数据,则有多少个表,则相对应的得有多少个宿主结构数组和指示结构数组(列有NULL值),这样的话显得不够灵活。
所以目前打算研究下ODBC和ADO,这些都没用过,不知道那个方便些,在处理上也灵活,就是在查询后不需要针对不同表定义不同变量,可以像JDBC那样处理数据库。
我的意思就是能不能动态取值 ,不需要提前知道每张表里有什么字段,传个表名就可以批量的将数据读取出来然后存入EXCEL或者什么地方,类似有那种可以提前查出此表共有多少列,然后内循环遍历每一列,读一列插入EXCEL中,再用外循环while(!m_pRecordset->adoEOF);
这样我就不需要为每张表中的每一列写程序,而只需为所有表写一个通用的程序。谢谢大家,帮帮忙。
import jxl.*;
import jxl.write.*;
/**
* @author Ken
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CreateXLS {
public static void main(String[] args) {
try {
//open file.
WritableWorkbook book = Workbook.createWorkbook(new File("d:/Test.xls"));
//create Sheet named "Sheet_1". 0 means this is 1st page.
WritableSheet sheet = book.createSheet("Sheet_1", 0);
//define cell column and row in Label Constructor, and cell content write "test".
//cell is 1st-Column,1st-Row. value is "test".
Label label = new Label(0, 0, "test");
//add defined cell above to sheet instance.
sheet.addCell(label);
//create cell using add numeric. WARN:necessarily use integrated package-path, otherwise will be throws path-error.
//cell is 2nd-Column, 1st-Row. value is 789.123.
jxl.write.Number number = new jxl.write.Number(1, 0, 789.123);
//add defined cell above to sheet instance.
sheet.addCell(number);
//add defined all cell above to case.
book.write();
//close file case.
book.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}