JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Tools  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 如何用POI讀取修改有巨集的excel檔?
huangyenlun





發文: 40
積分: 0
於 2006-10-22 01:36 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我有一個excel檔要當成範本,要利用這個範本的格式填入值並複製一份,於是我用了以下的方式
1
2
3
4
5
6
7
8
9
10
11
12
FileInputStream fileIn = new FileInputStream("E:/1.xls");
HSSFWorkbook wb     = new HSSFWorkbook(fileIn);  
FileOutputStream fileOut = new FileOutputStream("E:/2.xls");
 
HSSFSheet sheet = wb.getSheetAt(0);      
HSSFRow row     = sheet.getRow(2);        
HSSFCell cell   = row.getCell((short)2);  
cell.setCellValue("abc");
  
wb.write(fileOut);  
fileIn.close();
fileOut.close();


如果是一般沒巨集的excel檔那這一隻程式就可以將1.xls複製到2.xls,並填入我想要填的值,
要是有巨集的話在HSSFWorkbook wb = new HSSFWorkbook(fileIn);就會發生Exception如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
[WARNING] Unknown Ptg 0 (0)
[WARNING] Unknown Ptg 0 (0)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg 3c (60)
[WARNING] Unknown Ptg 0 (0)
[WARNING] Unknown Ptg ffffff8b (-117)
[WARNING] Unknown Ptg 3d (61)
[WARNING] Unknown Ptg 3d (61)
[WARNING] Unknown Ptg 11 (17)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg 34 (52)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg 3c (60)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg 3d (61)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg ffffffff (-1)
[WARNING] Unknown Ptg 30 (48)
[WARNING] Unknown Ptg 30 (48)
[WARNING] Unknown Ptg 48 (72)
[WARNING] Unknown Ptg 30 (48)
[WARNING] Unknown Ptg 34 (52)
[WARNING] Unknown Ptg ffffffe8 (-24)
[WARNING] Unknown Ptg ffffffeb (-21)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg 30 (48)
[WARNING] Unknown Ptg 0 (0)
[WARNING] Unknown Ptg 52 (82)
[WARNING] Unknown Ptg 0 (0)
[WARNING] Unknown Ptg 0 (0)
[WARNING] Unknown Ptg fffffff3 (-13)
[WARNING] Unknown Ptg ffffffe1 (-31)
[WARNING] Unknown Ptg fffffff7 (-9)
[WARNING] Unknown Ptg ffffffc4 (-60)
java.lang.reflect.InvocationTargetException
  at sun.reflect.GeneratedConstructorAccessor5.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
  at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
  at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
  at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
  at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:130)
  at com.ctf.util.TestUtil.main(TestUtil.java:24)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 29696
  at org.apache.poi.hssf.record.formula.FuncPtg.<init>(FuncPtg.java:59)
  at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:209)
  at org.apache.poi.hssf.record.NameRecord.getParsedExpressionTokens(NameRecord.java:808)
  at org.apache.poi.hssf.record.NameRecord.fillFields(NameRecord.java:780)
  at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
  at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
  at org.apache.poi.hssf.record.NameRecord.<init>(NameRecord.java:142)
  ... 8 more
Unable to construct record instance, the following exception occured: null
 


希望各位能告訴我要如何解決讀取修改excel的方式.....
感激不盡,謝謝!


reply to postreply to post
作者 Re:如何用POI讀取修改有巨集的excel檔? [Re:huangyenlun]
雨末星塵





發文: 5
積分: 0
於 2009-09-22 15:24 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最近也碰到這個問題耶!!
發文的兄臺有找到解決的方法嗎?!


reply to postreply to post
作者 Re:如何用POI讀取修改有巨集的excel檔? [Re:雨末星塵]
huangyenlun





發文: 40
積分: 0
於 2009-09-22 17:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
很不幸的
沒有ㄟ


reply to postreply to post
作者 Re:如何用POI讀取修改有巨集的excel檔? [Re:雨末星塵]
sukis47





發文: 1
積分: 0
於 2009-12-16 23:54 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最近也遇到這樣的問題
不知道有沒有解決的方法

還是說 有其他的方法可以修改巨集

thanks!!~


reply to postreply to post
作者 Re:如何用POI讀取修改有巨集的excel檔? [Re:huangyenlun]
hammer





發文: 19
積分: 0
於 2010-11-26 15:57 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我也遇到這問題,後來發現是少了幾個jar檔
除了poi.jar本身之外,
poi-ooxml.jar、poi-ooxml-schemas.jar、poi-scratchpad.jar
也都匯入再執行便沒問題了,至於到底是因為少了哪個,就沒去試囉


reply to postreply to post
» JWorld@TW »  Java Tools

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8