Quantcast
Viewing all 1288 articles
Browse latest View live

What does effectExtent mean if there's no effects?

Hi all;

In the file ATE-3548.docx two of the images have the effectExtent set to a non-zero b value. But as best I can tell, there's effect props. So what does this mean?

<w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0"><wp:extent cx="1800225" cy="1007745"/><wp:effectExtent l="0" t="0" r="0" b="3175"/><wp:docPr id="281" name="[path'),_height=1200)]8245.jpg"/><wp:cNvGraphicFramePr/><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="13" name="[path'),_height=1200)]8245.jpg"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="rId8"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="1800225" cy="1007745"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing>

thanks - dave


What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing




How to read and update chart's title in an excel file using DocumentFormat.OpenXml

Dear all,

I have an excel file with chart inside of it. I have to use DocumentFormat.OpenXml and pragmatically update the chart's title inside the excel file. I would appreciate if you could share sample code or your ideas or article(s) or any information with regards to this. Thank you so much for your help and support!


Narayana Reddy G

Productivity Tool Reflect Code Returns Huge Code

Hello,

When I run the Open XML SDK Reflect Code in the Productivity tool for the simplest word document that I can create (1 line of text), I get code with ~2000 lines. Is this right?

Thank you!

PS. I don't know what part of the code would be relevant to include as a snippet. 

Create an Excel Spreadsheet with an image on the First Header with Open Xml

Hello,

I have been trying to make a supposedly simple task of adding an image to the left of the First Header in an Excel Document, but i can't seem to accomplish it.

I have seen a few examples of inserting images but all of them are to insert an image to cells, i also tried to use Code Reflector from the OpenXML SDK Tools, but no clue in making it work. I have been able to insert some text on the header but i have no clue on how to do the same with an image. What i'm looking to acomplish is to have an image on the left side of the First Header and a Title on the right side of the header.

Can someone please shed some light on this with an actual working example?

This is the code i have working to create the excel Document with data from a DataTable

private MemoryStream CreateSummaryExcelDoc(DataTable dataTable)
        {
            MemoryStream s = new MemoryStream();

            //Create excel document
            using (SpreadsheetDocument excelDocument =
                SpreadsheetDocument.Create(s, SpreadsheetDocumentType.Workbook, true))
            {

                var workbookPart = excelDocument.AddWorkbookPart();
                excelDocument.WorkbookPart.Workbook = new Workbook();
                excelDocument.WorkbookPart.Workbook.Sheets = new Sheets();

                var sheetPart = excelDocument.WorkbookPart.AddNewPart<WorksheetPart>();

                var sheetData = new SheetData();
                sheetPart.Worksheet = new Worksheet(sheetData);
                Worksheet ws = sheetPart.Worksheet;

                // Header Text to Insert
                var textToInsert = "&R&B&18My Header Text"; // &R-Right Section f the Header &B- Bold &18-Font Size
                // Insert text to FirstHeader
                InsertHeaderFooter(ws, HeaderType.FirstHeader, textToInsert);

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

                string relationshipId = excelDocument.WorkbookPart.GetIdOfPart(sheetPart);
                // Create My Sheet
                Sheet sheet = new Sheet() { Id = relationshipId, SheetId = 1, Name = "My Sheet" };
                sheets.Append(sheet);

                // Table Header Row
                Row headerRow = new Row();
                // Insert the columns 
                List<String> columns = new List<string>();
                foreach (DataColumn column in dataTable.Columns)
                {
                    columns.Add(column.ColumnName);

                    Cell cell = new Cell();
                    cell.DataType = CellValues.String; 
                    cell.CellValue = new CellValue(column.ColumnName);
                    headerRow.AppendChild(cell);
                }

                sheetData.AppendChild(headerRow);

                // Insert data
                foreach (DataRow dsrow in dataTable.Rows)
                {
                    Row newRow = new Row();
                    foreach (String col in columns)
                    {
                        Cell cell = new Cell();
                        cell.DataType = CellValues.String; 
                        cell.CellValue = new CellValue(dsrow[col].ToString()); 
                        newRow.AppendChild(cell);
                    }

                    sheetData.AppendChild(newRow);
                }
            }

            return s;
        }

And this is function to add text to an Header.

private static void InsertHeaderFooter(Worksheet ws, HeaderType type, String textToInsert)
        {           
            HeaderFooter hf = ws.Descendants<HeaderFooter>().FirstOrDefault();
            if (hf == null)
            {
                hf = new HeaderFooter();
                ws.AppendChild<HeaderFooter>(hf);
            }

            // The HeaderFooter node should be there, at this point!
            if (hf != null)
            {
                // You've found the node. Now add the header or footer.
                // Deal with the attributes first:
                switch (type)
                {
                    case HeaderType.EvenHeader:
                    case HeaderType.EvenFooter:
                    case HeaderType.OddHeader:
                    case HeaderType.OddFooter:
                        // Even or odd only? Add a differentOddEven attribute and set 
                        // it to "1".
                        hf.DifferentOddEven = true;
                        break;

                    case HeaderType.FirstFooter:
                    case HeaderType.FirstHeader:
                        hf.DifferentFirst = true;
                        break;
                }

                switch (type)
                {
                    // This code creates new header elements, even if they
                    // already exist. Either way, you end up with a 
                    // "fresh" element.
                    case HeaderType.AllHeader:
                        hf.EvenHeader = new EvenHeader();
                        hf.EvenHeader.Text = textToInsert;

                        hf.OddHeader = new OddHeader();
                        hf.OddHeader.Text = textToInsert;
                        break;

                    case HeaderType.AllFooter:
                        hf.EvenFooter = new EvenFooter();
                        hf.EvenFooter.Text = textToInsert;

                        hf.OddFooter = new OddFooter();
                        hf.OddFooter.Text = textToInsert;
                        break;

                    case HeaderType.EvenFooter:
                        hf.EvenFooter = new EvenFooter();
                        hf.EvenFooter.Text = textToInsert;
                        break;

                    case HeaderType.EvenHeader:
                        hf.EvenHeader = new EvenHeader();
                        hf.EvenHeader.Text = textToInsert;
                        break;

                    case HeaderType.OddFooter:
                        hf.OddFooter = new OddFooter();
                        hf.OddFooter.Text = textToInsert;
                        break;

                    case HeaderType.OddHeader:
                        hf.OddHeader = new OddHeader();
                        hf.OddHeader.Text = textToInsert;
                        break;

                    case HeaderType.FirstHeader:
                        hf.FirstHeader = new FirstHeader();
                        hf.FirstHeader.Text = textToInsert;
                        break;

                    case HeaderType.FirstFooter:
                        hf.FirstFooter = new FirstFooter();
                        hf.FirstFooter.Text = textToInsert;
                        break;
                }
            }
            ws.Save();
        }

I appreciate any kind of help in this matter. Thanks!

How can I use openxml to update a MergeField in a template docx file please?

Hi All,

I got the following issue that need your hand.

I have a *.docx file as a template, with MergeField "NameField" inside.

May I ask, how can I use openxml to :

1. load this template document

2. locate the MregeField and update it

3. save the document into another name

Can anyone give me some advise or any sample code for reference please?

Many thanks

OpenXML PowerPoint SlideIdList InsertAfter : Operation is not valid due to the current state of the object.

I am using C# OpenXML for PowerPoint creation.

I am having right Previous SlideId. Trying to insert slide next to Previous SlideId using SlideIdList.InsertAfter method, that throws exception, Operation is not valid due to the current state of the object.

Sorry I cannot share the code due to security from my office.

How to delete all data in Excel file with Open Xml Sdk

Hi Team,

I want to delete the data from excel sheet data from open xml.

Please guide me,not only single cell ,want to to delete entire data from one specified sheet and save it.

Not working code:

worksheet = GetWorksheet(ref wbPart, ref sheet, ref worksheetPart, ref worksheet, "Sheet Name", document);
 worksheet.ClearAllAttributes();

thanks

Word dropdown, set selection

Plain and simply, I have a c:\dropdowntest.docx file that has nothing but one single dropdown list. The dropdown list has two options, "Option1" and "Option2". The file is saved so that "Option1" is selected. How do I select the "Option2" by using the Open XML SDK in C#?

Here's a start for the code, so I'm for example able to refer to the dropdown list:

privatestaticvoidLoopElements(WordprocessingDocument wordDocument){List<SdtElement> sdtelements = wordDocument.MainDocumentPart.Document.Descendants<SdtElement>().ToList();foreach(var contentcontrol in sdtelements){var listitems = contentcontrol.Descendants<ListItem>().ToList();if(listitems.Count>0){SdtRun xStdRun =(SdtRun)contentcontrol;


Update data from embedded chart in a PowerPoint with C# OpenXML

Hello,

I would like to update data from a chart into a powerpoint template.

I try many things to access the embedded data but i don't know how access it. 

When, i browsed the different part of the slide i founded in OleObject. Is it in this object that the data was store or maybe in the embedObjectPart ?

For information, the template use Think-Cell plugin.

My goal is to automate the generation of a PPT based on a template.

Thanks in advance !

How to replace random placeholders in word document using OpenXML and C#

I have a requirement in my MVC application where I want to programmatically replace placeholders with text or images from DB in a predefined document template.
Scenario: The application needs to generate one report based on some survey questionnaire answers. Report should be generated from a predefined document template(.docx) file available with all styling and formatting applied. Now I want to read this template, search for the placeholders and replace it with appropriate data without disturbing its formation and style.

How to achieve this using OpenXML SDK methods? I don’t want to use any third party tools. I did some R&D on google and tried few options. Tried using Stream, reading all text and then replace but it disturbs the document format. Also tried using searching placeholders in paragraphs, Runs, Text Descendants but with this it does not replace all the placeholders. some placeholders get ignored. Also replaced text is not getting reflected in final report document. How do we save word documents using OpemXML?

Please suggest as I have already spent lot of time figuring out the proper solution to my query.

How to add a HTML content into Shape with Open XML in Power Point?

Hello,

I have been working since a couple of years with Open XML, but using Word Processing. Now I am trying to apply the same configuration to Power Point Presentation.

I would like to know if it is possible to add HTML content into a Shape in OpenXML.

Are there equivalent code for this?

((MainDocumentPart)xmlPart).AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, altChunkId);

This could be the result code in PowerPoint (slide1.xml)

<p:sp><p:nvSpPr><p:cNvPr id="4" name="IIIIDDD" /><p:cNvSpPr txBox="1" /><p:nvPr /></p:nvSpPr><p:spPr><a:xfrm><a:off x="432329" y="4131204" /><a:ext cx="11243204" cy="2574395" /></a:xfrm><a:prstGeom prst="rect"><a:avLst /></a:prstGeom></p:spPr><p:txBody><a:bodyPr wrap="square" /><a:p><a:r><a:t>&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;meta charset='utf-8'/&gt;&lt;/head&gt;&lt;body&gt;&lt;table cellspacing='0' cellpadding='0' widht='100%' style='width:100%;border:none;border-collapse:collapse;'&gt;&lt;thead style='background-color:#E0E1E1;color:#343B45;font-size:12px;font-weight:bold;'&gt;&lt;tr &gt;&lt;td style='padding-left:10px;padding-right:10px;border:none;border-collapse:collapse;' valign='middle'&gt;&lt;span&gt;Attachments&lt;/span&gt;&lt;/td&gt;&lt;td style='padding-left:10px;padding-right:10px;border:none;border-collapse:collapse;' valign='middle'&gt;&lt;span&gt;ID&lt;/span&gt;&lt;/td&gt;&lt;td style='padding-left:10px;padding-right:10px;border:none;border-collapse:collapse;' valign='middle'&gt;&lt;span&gt;Title&lt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</a:t></a:r><a:endParaRPr /></a:p></p:txBody></p:sp>
Obviously, the code above returns an error on Power point.

Thank you!






Error in installing OpenXML 2.10.1 using NuGet in Visual Studio 2010

Hi,

I'm fairly new to Visual Studio projects.

Due to limitations on my project, I have to use Visual Studio 2010 and implement OpenXML version 2.10.1.

I installed NuGet Manager to install OpenXML 2.10.1 in Visual Studio 2010.


Unfortunately I encounter error:

'DocumentFormat.OpenXml' already has a dependency defined for 'System.IO.Packaging'.

When I use the NuGet Console, I encounter this error:

Install-Package : 'DocumentFormat.OpenXml' already has a dependency defined for 'System.IO.Packaging'.
At line:1 char:1
+ Install-Package DocumentFormat.OpenXml -Version 2.10.1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
 

Currently we have .NET 4.0 version.

As I understand, System.IO.Packaging is already included in WindowsBase for .NET 4.0.


Am I missing other Dependencies to add or some other configuration or steps?

Thank you,

JMikko



How to identify if the document has embeded images using openxml and C#

Dear team 

i want to check if the document has embeded images, can please share any code snippet ?

Thanks in advanced

Prasad

Why openxml unable to load document if it has invalid hyperlink ?

Dear team

my document has hyperlinks in it, some are valid and some are invalid.

when i trying to load that document in openxml, it throws an exception.

Please suggest, how to resolve this issue

Thanks in advanced

Prasad

openxml-issue-with-cellstyle

I'm trying to define a CellStyle within a completly empty spreadsheet. For the CellFormat I use the following code:

var workbookStylesPart = spreadsheetDocument.WorkbookPart.GetPartsOfType<WorkbookStylesPart>().First();
        //create default font for links
        Font font2 = new Font();
        Underline underline1 = new Underline();
        FontSize fontSize2 = new FontSize() { Val = 11D };
        Color color2 = new Color() { Theme = (UInt32Value)10U };
        FontName fontName2 = new FontName() { Val = "Calibri" };
        FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering() { Val = 2 };
        FontScheme fontScheme2 = new FontScheme() { Val = FontSchemeValues.Minor };
        font2.Append(underline1);
        font2.Append(fontSize2);
        font2.Append(color2);
        font2.Append(fontName2);
        font2.Append(fontFamilyNumbering2);
        font2.Append(fontScheme2);

        workbookStylesPart.Stylesheet.Fonts.Append(font2);
        int fontId = workbookStylesPart.Stylesheet.Fonts.Count() - 1;

        CellFormat copy = (CellFormat)workbookStylesPart.Stylesheet.CellFormats.FirstOrDefault().Clone();
        copy.FontId = Convert.ToUInt32(fontId);

        workbookStylesPart.Stylesheet.CellFormats.Append(copy);

This all works fine, I can apply this cellformat to a cell and it is properly formatted, but as soon as I open try to add this to a CellStyle my Spreadsheet is broken and I can't open it anymore. This is how I add the CellStyle:

 workbookStylesPart.Stylesheet.CellFormats.Append(copy);
        int cellFormatId = workbookStylesPart.Stylesheet.CellFormats.Count() - 1;

        CellStyle cellStyle2 = new CellStyle() { Name = "linkformat", FormatId = Convert.ToUInt32(cellFormatId), BuiltinId = (UInt32Value)0U };
If I change the FormatId back to the value "1U" it works again. Does anyone have an idea how I can get this to work?



OpenXML SpreadsheetDocument Header and Footer

I am able to edit the document with OpenXML WordprocessingDocument and remove then add back the header and footer with the updated company information.

I am trying to do the same for OpenXML SpreadsheetDocument, but I can't figure out how to remove/delete the existing header and footer. I see the DeletePart as part of the OpenXmlPartContainer which is part of OpenXmlPart : OpenXmlPartContainer. The spreadsheets have header and footers, but I don't see how to access them.

Sample code creates a corrupt file on Open XML SDK newest version

This sample code is out of date docs.microsoft.com/en-us/office/open-xml/how-to-create-a-spreadsheet-document-by-providing-a-file-name#sample-code

How to format excel cell with text color,font,alignment and number format etc using open xml sdk 2.5

Hi,

I am new to office open xml. I have to read excel and format cell with text color,font,alignment and number format etc.This should apply to more than one sheet in the excel. Please post me if you have any sample code.

Thanks,

How to add colour for bullet list in word document using openxml

Hi,

How to add colour for bullet list in word document using openxml.I am able to add colour to the text in the bullet list but the colour is not reflecting the bullets.Thanks in advance.

Thanks 

ashish jacob 

Trying to open word document throws InvalidDataException

I'm trying to open a .doc file using OpenXML and I am getting the following error:

System.IO.InvalidDataException: 'Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory.'

My code is really simple...

var filePath = "C:\\[Rest-Of-Path]\\file.doc"
var wordDocument = WordprocessingDocument.Open(filePath, false);

What could be causing this error? Thanks!

Viewing all 1288 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>