質問編集履歴
2
タグの更新
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
アドバイス後更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -81,3 +81,79 @@
|
|
81
81
|
どのようにしたら実現できますでしょうか?
|
82
82
|
|
83
83
|
ご教授お願いします。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
#ishi9様のアドバイス後
|
88
|
+
|
89
|
+
```C#
|
90
|
+
|
91
|
+
static void Main(string[] args)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
var templateName = "テスト.xlsx";
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
var byteArray = System.IO.File.ReadAllBytes(templateName);
|
100
|
+
|
101
|
+
var templateSheetName = "Sheet1";
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(templateName, true))
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
WorkbookPart workbookPart = spreadSheet.WorkbookPart;
|
110
|
+
|
111
|
+
Sheet targetSheet = (Sheet)spreadSheet.WorkbookPart.Workbook.Sheets.Elements<Sheet>().Where(s => s.Name == templateSheetName).FirstOrDefault();
|
112
|
+
|
113
|
+
if (targetSheet == null)
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
return;
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
WorksheetPart worksheetPart = (WorksheetPart)(workbookPart.GetPartById(targetSheet.Id));
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
|
128
|
+
|
129
|
+
var refRowIndex = 4;
|
130
|
+
|
131
|
+
var iEndRowIndex = 12;
|
132
|
+
|
133
|
+
Row refRow = worksheetPart.Worksheet.Descendants<Row>().Where(r => r.RowIndex == refRowIndex).First();
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
refRow.Remove();
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
for (int index = refRowIndex + 1; index <= iEndRowIndex; index++)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
Row refRow1 = worksheetPart.Worksheet.Descendants<Row>().Where(r => r.RowIndex == index).First();
|
146
|
+
|
147
|
+
refRow1.RowIndex.Value--;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
worksheetPart.Worksheet.Save();
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
```
|