public static void addWordFile(string fileName, string tableDoc) { using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, true)) { WorkbookPart wbPart = document.WorkbookPart; // Find the sheet with the supplied name, and then use that // Sheet object to retrieve a reference to the first worksheet. Sheet theSheet = wbPart.Workbook.Descendants<Sheet>(). Where(s => s.Name == "Test4").FirstOrDefault(); // Throw an exception if there is no sheet. if (theSheet == null) { throw new ArgumentException("sheetName"); } // Retrieve a reference to the worksheet part. WorksheetPart wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id)); EmbeddedPackagePart newEmbeddedPackagePart = wsPart.AddNewPart<EmbeddedPackagePart>(@"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "rId100"); newEmbeddedPackagePart.FeedData(File.Open(@tableDoc, FileMode.Open)); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)