openxml

How to replace an Paragraph's text using OpenXML Sdk

不羁的心 提交于 2019-12-05 23:26:04
问题 I am parsing some Openxml word documents using the .Net OpenXml SDK 2.0. I need to replace certain sentences with other sentences as part of the processing. While iterating over the paragraphs, I know when I've found something I need to replace, but I am stumped as to how I can replace it. For example, lets say I need to replace the sentence "a contract exclusively for construction work that is not building work." with a html snippet to a Sharepoint Reusable content below. <span class="ms

Excel add data to WorksheetPart in code behind

荒凉一梦 提交于 2019-12-05 22:47:21
问题 Hello guys I am creating an Excel file with 3 worksheets in the following code. using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Create(path + @"\UrlReport.xlsx", SpreadsheetDocumentType.Workbook)) { // create the workbook spreadSheet.AddWorkbookPart(); spreadSheet.WorkbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook(); // CREATE FIRST SHEET WorksheetPart newWorksheetPart1 = spreadSheet.WorkbookPart.AddNewPart<WorksheetPart>(); newWorksheetPart1.Worksheet = new

Insert an image into word document using open xml and C#

╄→尐↘猪︶ㄣ 提交于 2019-12-05 22:33:00
I have the following code trying to insert an image into a word document using open xml: private void AddImageToBody(ImagePart imagePart) { // Define the reference of the image. var element = new Drawing( new Inline( new Extent() { Cx = ConvertToEmu(640), Cy = ConvertToEmu(480) }, new EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }, new DocProperties() { Id = (UInt32Value)1U, Name = "Picture 1" }, new NonVisualGraphicFrameDrawingProperties( new GraphicFrameLocks() { NoChangeAspect = true } ), new Graphic( new GraphicData( new Picture( new

C# OpenXML (Word) Table AutoFit to Window

我怕爱的太早我们不能终老 提交于 2019-12-05 22:32:18
问题 Open a Word (2007/2010) document that has a table in it, select the table and right click, select AutoFit-->AutoFit to Window How can I implement this action in C# using the OpenXML SDK 2.5? 回答1: You can set the width of the table to 100% of the page, or 5000 fiftieths-of-a-percent. Table table = ... TableWidth width = table.GetDescendents<TableWidth>().First(); width.Width = "5000"; width.Type = TableWidthUnitValues.Pct; 来源: https://stackoverflow.com/questions/18025424/c-sharp-openxml-word

Why does OpenXML read rows twice

流过昼夜 提交于 2019-12-05 22:25:17
I count rows in two worksheets like this: foreach (WorksheetPart worksheetPart in workbookPart.WorksheetParts) { OpenXmlPartReader reader = new OpenXmlPartReader(worksheetPart); if (count == 0) { while (reader.Read()) { if (reader.ElementType == typeof(Row)) { count_first++; } } } else if (count == 1) { while (reader.Read()) { if (reader.ElementType == typeof(Row)) { count_second++; } } } count++; } For both worksheets in count_first and count_second I get twice as much as there are rows with data. Why is that and what does it actually mean? Does it mean that OpenXML parses each list twice?

ClosedXML add image

早过忘川 提交于 2019-12-05 20:02:24
I am able to add in an image to an excel spreadsheet by using OpenXML. However for the rest of the program I use ClosedXML to add data. I can add data at a specific cell using the column and row index. If I can add an image to an excel (It currently is a separate layer it seems, hovering over cells), how can I add it to a cell using ClosedXML? //Adds an image to the excel file public void AddImageToExcel(SpreadsheetDocument sd, MemoryStream imagestream) { DrawingsPart dp = sd.WorkbookPart.WorksheetParts.First().AddNewPart<DrawingsPart>(); ImagePart imgp = dp.AddImagePart(ImagePartType.Jpeg, sd

EPPlus not caluculating formula output after binding

穿精又带淫゛_ 提交于 2019-12-05 19:18:10
I am using EPPlus. I am stuck at cell formulas. My code is below: ExcelPackage pck = new ExcelPackage(@"D:\MYSheets\EmptyFile.xlsx"); var ws = pck.Workbook.Worksheets["MySheet"]; ws.Cells["A3"].Value = "2.3"; ws.Cells["A4"].Value = "10.2"; ws.Cells["A5"].Formula = "=SUM(A3:A4)"; ws.Cells["A5"].Style.Numberformat.Format = "#,##0.00"; pck.Save(); When I open Excel, by default, A5 cell is not calculating the sum of A3 and A4. Unless I modify the A3 and/or A4 cells, the A5 cell remains not calculated. I tried using the following code but it didn't work for me: ws.Workbook.CalcMode = ExcelCalcMode

copying openXML image from one document to another

前提是你 提交于 2019-12-05 18:54:10
We have conditional Footers that INCLUDETEXT based on the client: IF $CLIENT = "CLIENT1" "{INCLUDETEXT "CLIENT1HEADER.DOCX"}" "" Depending on our document, there could be a varying amount of IF/ELSE , and these all work correctly for merging the correct files in the correct place. However, some of these documents may have client specific images/branding, which also need to be copied across from the INCLUDETEXT file. Below is the method that is called to replace any Picture elements that exist in the IEnumerable<Run> that is copied from the Source document to the Target document. The image is

OPEN XML add custom not visible data to paragraph/table

两盒软妹~` 提交于 2019-12-05 16:14:19
Is there a way to store additional data for a paragraph, that would be persisted after user opens and saves a document in MS Word. Ive been using CusotmXML for this, but it turns out that this is no logner possible due to the fact that MS-Word strips all CusotmXML elements from the document structure. Every single paragraph or a table has an ID that I would like to "pair back" to my data-source. So later when I read the docx again I can identify origins of every unchanged paragraph/table in the document. A possibility would be to insert a SET field. This creates a bookmark in the document to

Read only or Lock the particular cells or rows using open xml sdk

空扰寡人 提交于 2019-12-05 15:22:17
I am using open xml sdk to export excel. I get the excel file and copying that file to another place and then I'm inserting new rows with the data. I should make that rows as read only (or I've to lock) using open xml sdk.. How to do that ? Jeeva Jsb I've referred the following link Excel File Password Protection with Open XML SDK . Here I gave you full code to open the file from directory and insert cells. Here I've inserted only one cell. You can insert as you want. Here I've inserted locked cells. Find this one, it'll very helpful to you.. Note : Here I've mentioned the code only to read