package org.liuqing.excel.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Random;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
/**
*
* @author liuqing
* @version 1.0
* @see 导出文件值
* @datetime 2012-3-12 下午9:56:31
*/
public class ExportFileUtil {
private static Log log = LogFactoryImpl.getLog(ExportFileUtil.class);
static Properties uploadConf = new Properties();
static {
try {
/**
* 加载配置文件
*/
log.info("loading excel config .......");
uploadConf.load(ExportFileUtil.class.getResourceAsStream("/org/liuqing/excel/util/conf.properties"));
log.info("load configuration successfully ...!");
}
catch (IOException e) {
e.printStackTrace();
}
}
/**
* 自动创建文件夹
* @param fileName
* @return boolean
*/
public static boolean isExitsFile(String fileName) {
File fileDir = new File(uploadConf.getProperty("path"));
fileDir.mkdirs();
File file = new File(fileDir.getPath() + File.separator + fileName);
return file.exists();
}
public static void main(String args[]) throws IOException {
File file = new File(uploadConf.getProperty("path") + File.separator + "fudmafda.xls");
FileOutputStream fos = new FileOutputStream(file);
PrintWriter osw=new PrintWriter(fos);
for (int i = 1 ; i < 600000; i++) {
osw.println("aaa\tbb\tccc\tddd\teee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tfff\tr\tn\r\n");
if (i % 100 == 0) {
osw.flush();
}
}
osw.close();
/**
System.out.println(isExitsFile("/201203122258116313653793767960715.xls"));
FileOutputStream outputStream = new FileOutputStream(
new File(String.valueOf(uploadConf.get("path")) +
File.separator + randomFileName()));
HSSFWorkbook hssf = new HSSFWorkbook();
Sheet sheet = hssf.createSheet("excelSheet");
for (int i = 0 ; i < 5000; i++) {
Row row = sheet.createRow(i);
for (int u = 0 ; u < 200 ; u++) {
Cell cell = row.createCell(u);
cell.setCellValue(u + "===如果是这种需求如果是这种需求,考虑方案的时候就不应该局限在Java的Tools里面,因为Java里面那些操作excel的工具就只是一个权益之计,考虑方案的时候就不应该局限在Java的Tools里面,因为Java里面那些操作excel的工具就只是一个权益之计===============" + u);
}
}
hssf.write(outputStream);
outputStream.close();
System.out.println(ExportFileUtil.randomFileName());
System.out.println(uploadConf.getProperty("path"));
**/
/**
FileInputStream input = new FileInputStream(
new File(String.valueOf(uploadConf.get("path")) +
File.separator + "201203122258116313653793767960715.xls"));
POIFSFileSystem poif = new POIFSFileSystem(input);
HSSFWorkbook wb=new HSSFWorkbook(poif);
Sheet sheet = wb.getSheetAt(0);
int last = sheet.getLastRowNum();
int us = last + 200;
for (; last < us;last++) {
Row row = sheet.createRow(last);
for (int u = 0 ; u < 254 ; u++) {
Cell cell = row.createCell(u);
cell.setCellValue(" uml=2222222222===== " + u);
}
}
OutputStream output = new FileOutputStream(
new File(String.valueOf(uploadConf.get("path")) +
File.separator + "201203122258116313653793767960715.xls"));
BufferedOutputStream bufOutput = new BufferedOutputStream(output);
wb.write(bufOutput);
output.close();
input.close();
**/
}
/**
* 生文件唯一文件名
* @return String
*/
public static String randomFileName() {
Random random = new Random();
long randomValue = random.nextLong();
randomValue = Math.abs(randomValue);
SimpleDateFormat simp = new SimpleDateFormat("yyyyMMddHHssmm");
String dateStr = simp.format(new Date());
String fileName = dateStr + randomValue + ".xls";
return fileName;
}
}