) zip.entries();
- while (en.hasMoreElements()) {
- ZipEntry ze = en.nextElement();
- if (!ze.getName().equals(entry)) {
- zos.putNextEntry(new ZipEntry(ze.getName()));
- InputStream is2 = null;
- try{
- is2 = zip.getInputStream(ze);
- copyStream(is2, zos);
- }finally {
- if (is2 != null){
- is2.close();
- }
- }
- }
- }
- zos.putNextEntry(new ZipEntry(entry));
- is = new FileInputStream(tmpfile);
- copyStream(is, zos);
- }finally {
- if (is != null){
- is.close();
- }
- if (zos != null){
- zos.close();
- }
- if (zip != null){
- zip.close();
- }
- }
- }
-
- private static void copyStream(InputStream in, OutputStream out)
- throws IOException {
- byte[] chunk = new byte[1024];
- int count;
- while ((count = in.read(chunk)) >= 0) {
- out.write(chunk, 0, count);
- }
- }
-
- /**
- * 在写入器中写入电子表格
- *
- */
- public static class SpreadsheetWriter {
- private final Writer _out;
- private int _rownum;
- private static String LINE_SEPARATOR = System
- .getProperty("line.separator");
-
- public SpreadsheetWriter(Writer out) {
- _out = out;
- }
-
- public void beginSheet() throws IOException {
- _out.write(""
- + "");
- _out.write("" + LINE_SEPARATOR);
- }
-
- public void endSheet() throws IOException {
- _out.write("");
- _out.write("");
- }
-
- /**
- * 插入新行
- *
- * @param rownum
- * 以0开始
- */
- public void insertRow(int rownum) throws IOException {
- _out.write("" + LINE_SEPARATOR);
- this._rownum = rownum;
- }
-
- /**
- * 插入行结束标志
- */
- public void endRow() throws IOException {
- _out.write("
" + LINE_SEPARATOR);
- }
-
- /**
- * 插入新列
- *
- * @param columnIndex
- * @param value
- * @param styleIndex
- * @throws IOException
- */
- public void createCell(int columnIndex, String value, int styleIndex)
- throws IOException {
- String ref = new CellReference(_rownum, columnIndex)
- .formatAsString();
- _out.write("");
- _out.write("" + encoderXML(value) + "");
- _out.write("");
- }
-
- public void createCell(int columnIndex, String value)
- throws IOException {
- createCell(columnIndex, value, -1);
- }
-
- public void createCell(int columnIndex, double value, int styleIndex)
- throws IOException {
- String ref = new CellReference(_rownum, columnIndex)
- .formatAsString();
- _out.write("");
- _out.write("" + value + "");
- _out.write("");
- }
-
- public void createCell(int columnIndex, double value)
- throws IOException {
- createCell(columnIndex, value, -1);
- }
-
- public void createCell(int columnIndex, Calendar value, int styleIndex)
- throws IOException {
- createCell(columnIndex, DateUtil.getExcelDate(value, false),
- styleIndex);
- }
- }
-
- // XML Encode
- private static final String[] xmlCode = new String[256];
-
- static {
- // Special characters
- xmlCode['\''] = "'";
- xmlCode['\"'] = "\""; // double quote
- xmlCode['&'] = "&"; // ampersand
- xmlCode['<'] = "<"; // lower than
- xmlCode['>'] = ">"; // greater than
- }
-
- /**
- *
- * Encode the given text into xml.
- *
- *
- * @param string the text to encode
- * @return the encoded string
- */
- public static String encoderXML(String string) {
- if (string == null) {
- return "";
- }
- int n = string.length();
- char character;
- String xmlchar;
- StringBuffer buffer = new StringBuffer();
- // loop over all the characters of the String.
- for (int i = 0; i < n; i++) {
- character = string.charAt(i);
- // the xmlcode of these characters are added to a StringBuffer
- // one by one
- try {
- xmlchar = xmlCode[character];
- if (xmlchar == null) {
- buffer.append(character);
- } else {
- buffer.append(xmlCode[character]);
- }
- } catch (ArrayIndexOutOfBoundsException aioobe) {
- buffer.append(character);
- }
- }
- return buffer.toString();
- }
-
-// /**
-// * 测试方法
-// */
-// public static void main(String[] args) throws Exception {
-//
-// String file = "E:/测试导出数据.xlsx";
-//
-// ExcelWriter writer = new ExcelWriter() {
-// @Override
-// public void generate() throws Exception {
-//
-// // 电子表格开始
-// this.beginSheet();
-//
-// for (int rownum = 0; rownum < 100; rownum++) {
-// // 插入新行
-// this.insertRow(rownum);
-//
-// // 建立新单元格,索引值从0开始,表示第一列
-// this.createCell(0, "第 " + rownum + " 行");
-// this.createCell(1, 34343.123456789);
-// this.createCell(2, "23.67%");
-// this.createCell(3, "12:12:23");
-// this.createCell(4, "2014-10-11 12:12:23");
-// this.createCell(5, "true");
-// this.createCell(6, "false");
-//
-// // 结束行
-// this.endRow();
-// }
-//
-// // 电子表格结束
-// this.endSheet();
-// }
-// };
-// writer.process(file);
-// }
-
-}