我期待使用Java以编程方式写入excel(.xls MS Excel 2003格式)文件.excel输出文件可能包含~200,000行,我打算将其分成多张纸(由于excel限制,每张64k行).
我尝试过使用apache POI API,但由于API对象模型,它似乎是一个内存耗尽.我被迫将单元格/工作表添加到内存中的工作簿对象中,只有添加了所有数据后,我才能将工作簿写入文件!以下是apache建议如何使用API编写excel文件的示例:
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
//Create a row and put some cells in it
Row row = sheet.createRow((short)0);
// Create a cell and put a value in it.
Cell cell = row.createCell(0);
cell.setCellValue(1);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
Run Code Online (Sandbox Code Playgroud)
显然,编写~20k行(每行有10-20列)给了我可怕的"java.lang.OutOfMemoryError:Java堆空间".
我尝试使用Xms和Xmx参数将XVM初始堆大小和最大堆大小增加为Xms512m和Xmx1024.仍然无法向文件写入超过150k行.
我正在寻找一种流式传输到excel文件的方法,而不是在将其写入磁盘之前在内存中构建整个文件,这有望节省大量内存.任何替代API或解决方案都将受到赞赏,但我仅限于使用java.谢谢!:)
我不清楚Clojure中的结构共享.下面是一个取自Clojure的欢乐的函数xconj(Great book BTW).
;;Building a naive binary search tree using recursion
(defn xconj [t v]
(cond
(nil? t) {:val v :L nil :R nil}
(< v (:val t)) {:val (:val t) :L (xconj (:L t) v) :R (:R t)}
:else {:val (:val t) :L (:L t) :R (xconj (:R t) v)}))
Run Code Online (Sandbox Code Playgroud)
如果定义了两个树t1和t2,如下所示.
(def t1 (xconj (xconj (xconj nil 5) 3) 2))
(def t2 (xconj t1 7))
Run Code Online (Sandbox Code Playgroud)
很明显,左子树由t1和t2共享
user> (identical? (:L t1) (:L t2))
true
Run Code Online (Sandbox Code Playgroud)
但是如果要创建一个新树t3,通过在t1的左子树中插入一个新值'1',如下所示:
(def t3 (xconj t1 1)) …Run Code Online (Sandbox Code Playgroud) 由于某种原因,我无法重置我的git工作目录中的一个特定文件!
开始:
我做了一个git reset - 现在,
$ git reset --hard
HEAD is now at 97b3164 Added clojure jars for personal tracking and also set clo
jure classpath in jaskirat.el
Run Code Online (Sandbox Code Playgroud)
硬重置后:
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: elpa-to-submit/color-theme.el
#
no changes added to commit (use "git add" and/or "git …Run Code Online (Sandbox Code Playgroud)