回答編集履歴

2

誤字

2016/09/12 05:22

投稿

ishi9
ishi9

スコア1294

test CHANGED
@@ -29,5 +29,3 @@
29
29
  ```
30
30
 
31
31
 
32
-
33
- https://teratail.com/questions/47701#

1

根本的に間違っていたため

2016/09/12 05:22

投稿

ishi9
ishi9

スコア1294

test CHANGED
@@ -1,14 +1,30 @@
1
- ここを参考にてみてくだ
1
+ ここにあるように下の行1行ずつ詰めるやり方かなそうです(標準には無さそう)
2
2
 
3
- [OpenBook](http://mitsutakauomi.com/?paged=2)
3
+ [Delete a row in Excel Sheet using OpenXML](https://social.msdn.microsoft.com/Forums/office/en-US/d4e654bf-3a62-49b2-99e3-0b62b9439786/delete-a-row-in-excel-sheet-using-openxml?forum=oxmlsdk)
4
4
 
5
5
 
6
6
 
7
7
  ```c#
8
8
 
9
- var sheet = workbook.GetSheetAt(0);
9
+ Row refRow = ((WorksheetPart)(workbookPart.GetPartById(theSheet.Id))).Worksheet.Descendants<Row>().Where(r => r.RowIndex == refRowIndex).First();
10
10
 
11
+
12
+
13
+ // delete row
14
+
15
+ refRow.Remove();
16
+
17
+
18
+
19
+ for (int index = refRowIndex + 1; index <= iEndRowIndex; index++)
20
+
21
+ {
22
+
23
+ Row refRow1 = workSheetPart.Worksheet.Descendants<Row>().Where(r => r.RowIndex == index).First();
24
+
11
- sheet.RemoveRow(sheet.GetRow(rowIndex));
25
+ refRow1.RowIndex.Value--;
26
+
27
+ }
12
28
 
13
29
  ```
14
30