如果存在带有Office Open xml的工作表数据格式,如下所示:
<sheetData>
<row r="1" spans="1:3" x14ac:dyDescent="0.25">
<c r="A1" t="s">
<v>0</v>
</c>
<c r="B1" t="s">
<v>1</v>
</c>
<c r="C1" t="s">
<v>2</v>
</c>
</row>
<row r="2" spans="1:3" x14ac:dyDescent="0.25">
<c r="A2">
<v>1</v>
</c>
<c r="B2">
<v>2</v>
</c>
<c r="C2">
<v>3</v>
</c>
</row>
<row r="3" spans="1:3" x14ac:dyDescent="0.25">
<c r="A3">
<v>4</v>
</c>
<c r="B3">
<v>5</v>
</c>
<c r="C3">
<v>6</v>
</c>
</row>
<row r="4" spans="1:3" x14ac:dyDescent="0.25">
<c r="A4">
<v>7</v>
</c>
<c r="B4">
<v>8</v>
</c>
<c r="C4">
<v>9</v>
</c>
</row>
</sheetData>
如何为epplus设置此xml以更改单元格值?
仅搜索epplus和Cells[IndexName].Value = "xx"
API。
一些epplus方法,例如:
ws.SetSheetDataXml = xml;
答案 0 :(得分:1)
您总是可以像这样访问和处理Worksheet
的XML:
var fi = new FileInfo(@"c:\temp\SomeExcelFile.xlsx");
using (var pck = new ExcelPackage(fi))
{
var workbook = pck.Workbook;
var ws = workbook.Worksheets.Add("Sheet1");
ws.Cells.LoadFromDataTable(datatable, true);
var xdoc = ws.WorksheetXml;
...
}
很显然,您必须小心使用它,以便在尝试保存时,Epplus不会感到不适。通常,直接将XML弄乱是Epplus无法做的事情的不得已。以下是一些示例:
How can I turn background error checking off for the Excel app object in EPPlus?
X-Axis label formatting issue while exporting Chart to Excel using EPPlus