回答編集履歴

1

状況により例外が発生するので、それを考慮したコードの修正。

2016/09/08 00:31

投稿

twck
twck

スコア314

test CHANGED
@@ -6,9 +6,15 @@
6
6
 
7
7
  ```C#
8
8
 
9
- using (MemoryStream ms = new MemoryStream(System.IO.File.ReadAllBytes(複写元のファイルパス))
9
+ using (MemoryStream ms = new MemoryStream()
10
10
 
11
11
  {
12
+
13
+ var bytes = System.IO.File.ReadAllBytes(複写元のファイルパス);
14
+
15
+ ms.Write(bytes, 0, bytes.Length);
16
+
17
+
12
18
 
13
19
  using (SpreadsheetDocument document = SpreadsheetDocument.Open(ms, true))
14
20
 
@@ -20,7 +26,7 @@
20
26
 
21
27
 
22
28
 
23
- System.IO.File.WriteAllBytes(複写先のファイルパス, ms.ToArray())
29
+ System.IO.File.WriteAllBytes(複写先のファイルパス, ms.ToArray());
24
30
 
25
31
  }
26
32