質問するログイン新規登録

質問編集履歴

3

createメソッドを使用するように変更

2024/03/27 06:59

投稿

kentosushi
kentosushi

スコア1

title CHANGED
File without changes
body CHANGED
@@ -18,38 +18,29 @@
18
18
  ### 該当のソースコード
19
19
 
20
20
  ```java
21
+ public class Main {
21
- public static void main(String[] args) throws Exception {
22
+ public static void main(String[] args) {
22
- System.out.print("start: main\r\n");
23
+ System.out.println("start: main");
23
24
 
24
- excelOpenXlsxPassword("C://GCS/template.xlsx", "abc");
25
-
26
- System.out.print("end: main\r\n");
27
- }
28
-
29
- /**
30
- * パスワード付きExcelファイルの読み込み&書き込み。
31
- * @param filePath Excelファイルのフルパス
32
- * @param password パスワード
33
- * @throws IOException
34
- */
35
- public static void excelOpenXlsxPassword(String filePath, String password) throws EncryptedDocumentException, IOException {
36
- FileInputStream fi = null;
25
+ FileInputStream in = null;
37
- POIFSFileSystem fileSystem = null;
38
- InputStream is = null;
39
- Workbook wb = null;
26
+ Workbook tempbook = null;
40
27
  try {
41
- fi = new FileInputStream(filePath);
28
+ in = new FileInputStream("test.xlsx");
29
+ tempbook = WorkbookFactory.create(in, "abc");
30
+ } catch (IOException e) {
42
- fileSystem = new POIFSFileSystem(fi);
31
+ System.out.print(e.toString());
43
- EncryptionInfo info = new EncryptionInfo(fileSystem);
32
+ } finally {
44
- Decryptor d = Decryptor.getInstance(info);
33
+ try {
45
- if (d.verifyPassword(password) == false) {
34
+ if (tempbook != null) {
35
+ tempbook.close();
36
+ }
37
+ } catch (IOException e) {
46
- System.out.println("パスワードを解除出来ませんした。");
38
+ System.out.print("終了処理入出力例外が発生!");
47
- return;
48
- }else{
49
- System.out.println("解除成功");
50
39
  }
40
+ }
51
- is = d.getDataStream(fileSystem);
41
+ System.out.println("読込完了");
52
- wb = new XSSFWorkbook(is);
42
+ }
43
+ }
53
44
  ```
54
45
 
55
46
  ### 試したこと

2

バージョン追記

2024/03/27 00:08

投稿

kentosushi
kentosushi

スコア1

title CHANGED
File without changes
body CHANGED
@@ -58,4 +58,7 @@
58
58
  US_export_policy.jar
59
59
  local_policy.jar
60
60
 
61
-
61
+ ### 補足情報
62
+ java 1.8.0_381
63
+ apache poi 5.2.3
64
+ jce_policy 8

1

不要なコードを削除

2024/03/26 11:11

投稿

kentosushi
kentosushi

スコア1

title CHANGED
File without changes
body CHANGED
@@ -21,21 +21,8 @@
21
21
  public static void main(String[] args) throws Exception {
22
22
  System.out.print("start: main\r\n");
23
23
 
24
- Workbook tempbook = null;
25
- try {
26
- excelOpenXlsxPassword("C://GCS/template.xlsx", "abc");
24
+ excelOpenXlsxPassword("C://GCS/template.xlsx", "abc");
27
- } catch (IOException e) {
25
+
28
- System.out.print("入出力例外が発生!");
29
- } finally {
30
- //--- テンプレートをクローズ --//
31
- try {
32
- if (tempbook != null) {
33
- tempbook.close();
34
- }
35
- } catch (IOException e) {
36
- System.out.print("終了処理で入出力例外が発生!");
37
- }
38
- }
39
26
  System.out.print("end: main\r\n");
40
27
  }
41
28