
























the project need create the Excel files.i try to use MS Lib in .net but it cost a lot of menory.so i get the JexcelApi and POI to create excel file,it is great.
this page is keep code,nothing else,:>
this is the process Class:
package jExcel;
import jxl.*;
import jxl.write.*;
import jxl.write.biff.RowsExceededException;
import java.io.*;
import java.util.*;
public class Export {/**
* Data Items
*/
private static List<String[]> items = new ArrayList<String[]>();/**
* Generate Items
*
* @param Address
* @param Zip
*/
public static void GenerateItem(String Address, String Zip) {
items.add(new String[]{Address,Zip});
}/**
* Export To Excel
*
* @param filepath
* @throws IOException
* @throws RowsExceededException
* @throws WriteException
*/
public static void ExportToExcel(String filepath) throws IOException,
RowsExceededException, WriteException {
File file = new File(filepath);
//check file exsist
if (file.exists()) {
}
else {this is the main function class:
import java.io.*;
import java.util.*;import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;import jExcel.*;public class ExApplication {static String s = "";
static BufferedReader input = new BufferedReader(new InputStreamReader(
System.in));static String getFilename() {
String temp = "";
File file = new File(".");
temp = file.getAbsolutePath().substring(0,
file.getAbsolutePath().lastIndexOf("\\"))
+ "\\";
Date day = new Date();
temp += day.toString().replace(" ", "").replace(":", "") + ".xls";
return temp;
}/**
* @param args
* @throws IOException
* @throws WriteException
* @throws RowsExceededException
*/
public static void main(String[] args) throws IOException,
RowsExceededException, WriteException {
System.out.println("Please input Address,Zip");
while (!s.toLowerCase().equals("done")) {
if (s.toLowerCase().indexOf(",") > -1) {
String[] temp = s.toLowerCase().split(",");
if (temp.length == 2) {
Export.GenerateItem(temp[0], temp[1]);
}
}
s = input.readLine();
}
if (s.toLowerCase().equals("done")) {
try {
String name = getFilename();
Export.ExportToExcel(name);
System.out.println("Create Complete File :" + name);
}
catch (Exception ex) {}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。