无法使用openxml excel C#为twoCellAnchor设置innerText

时间:2018-01-22 11:00:53

标签: c# excel openxml

我的要求是使用openxml c#更改excel中文本框的文本。我可以使用以下代码找到文本框:

WorkbookPart workbookPart = document.WorkbookPart;
                    Sheets sheets = workbookPart.Workbook.GetFirstChild<Sheets>();


//To add the month in the first KPMG sheet
string sheetName = "Test";
Sheet sheet1 = document.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>().Where(s => s.Name == sheetName).FirstOrDefault();

string relationshipId = sheet1.Id.Value;

WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(relationshipId);
var ocaElems = worksheetPart.DrawingsPart.WorksheetDrawing.Elements<TwoCellAnchor>();

foreach (TwoCellAnchor twoCellAnchor in ocaElems)
{
if (twoCellAnchor.InnerText.Contains("google"))
{
//twoCellAnchor.InnerText = "Ted Report - August";
//while setting innerText its showing error as set is not accessible
                                
}

                       
 }

0 个答案:

没有答案