Giter Club home page Giter Club logo

open-xml-docs's Introduction

Open XML documentation

This repo is the source markdown for documentation published at /office/open-xml/open-xml-sdk.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

open-xml-docs's People

Contributors

andreygolubkow avatar davidchesnut avatar dend avatar dereklh7 avatar eriawan avatar jdelauri avatar jimmy-hu avatar learn-build-service-prod[bot] avatar leocui9387 avatar lindalu-msft avatar lindexi avatar live1206 avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar mikeebowen avatar mikewaretena avatar mohitp930 avatar nxtn avatar olprod avatar p-kaczynski avatar rschoenrock avatar saisang avatar scottmcarthur avatar stephenbrentpeters avatar taojunshen avatar twsouthwick avatar v-alje avatar v-emilypr avatar vsc-service-account avatar xchimera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

open-xml-docs's Issues

Spreadsheet has an invalid format after inserting a chart (from examples)

Hallo,

I am trying to combine two of the examples

using a simple code:

const string fileName = @"c:\temp\test-data.xlsx";
// Execute the code from 
// https://docs.microsoft.com/en-US/office/open-xml/how-to-create-a-spreadsheet-document-by-providing-a-file-name
CreateDocumentExample.CreateSpreadsheetWorkbook(fileName);
var testData = new Dictionary<string, int> {{"Monday", 1}, {"Tuesday", 10}, {"Wednesday", 4}};
// Execute the code from 
// https://docs.microsoft.com/en-us/office/open-xml/how-to-insert-a-chart-into-a-spreadsheet
InsertChartExample.InsertChartInSpreadsheet(fileName, "mySheet", "Created Chart", testData);

and unfortunately the resulting file is not correct:
image
The log shows following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
	<logFileName>error219600_01.xml</logFileName>
	<summary>Fehler in Datei 'C:\Temp\test-data.xlsx'</summary>
	<repairedRecords>
		<repairedRecord>Reparierte Datensätze: Zeichnung von /xl/drawings/drawing1.xml-Part (Zeichnungsform)</repairedRecord>
	</repairedRecords>
</recoveryLog>

What could be wrong?
I have prepared also the code example here:
https://bitbucket.org/alexpuh/excelgraphfail/

With best regards,
Alexej Puchovski

Update APIs for v3.0 when released

do this, call the [MainDocumentPart](https://msdn.microsoft.com/library/office/documentformat.openxml.packaging.maindocumentpart.aspx) generic method, **GetPartsCountOfType**, and specify a kind of **WordprocessingCommentsPart**.

GetPartsCountOfType has been removed from the sdk in the 3.0 beta. This example will need to be updated.

For more context see: dotnet/Open-XML-SDK#1442

cant find Deleted Inserted

       using (WordprocessingDocument doc = WordprocessingDocument.Open("testd.docx", true))
        {
            var body = doc.MainDocumentPart.Document.Body;
            List<OpenXmlElement> changes =
           body.Descendants<ParagraphPropertiesChange>()
           //.Where(c => c.Author.Value == authorName)
           .Cast<OpenXmlElement>().ToList();   // number is 0

            List<OpenXmlElement> deletions =
            body.Descendants<Deleted>()
            //.Where(c => c.Author.Value == authorName)
            .Cast<OpenXmlElement>().ToList();   // number is 0

            var insertions =
           body.Descendants<Inserted>()
           //.Where(c => c.Author.Value == authorName)
           .Cast<OpenXmlElement>().ToList();  // number is 0

        }

testd.docx

API xref syntax not supported?

@lindalu-MSFT Other docs projects I've worked in (asp.net and dotnet) allow for <xref:...> syntax to reference APIs to automatically resolve names and ensure it exists. I tried doing that here, but it doesn't seem to work. Is there a way to hook that up? Or is it because I'm trying to run it locally?

Once this is available, we should

  • Update all references to APIs in the docs using this syntax

URI for inserting a new image in Word document refers to https instead of http

The example "how-to-insert-a-picture-into-a-word-processing-document" contains a namespace error for the URI.

         new A.PresetGeometry(
                                 new A.AdjustValueList()
                             ) { Preset = A.ShapeTypeValues.Rectangle }))
                 ) { Uri = "https://schemas.openxmlformats.org/drawingml/2006/picture" })

must be

         new A.PresetGeometry(
                                 new A.AdjustValueList()
                             ) { Preset = A.ShapeTypeValues.Rectangle }))
                 ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })

Then this example will work.

Clearing Pivot Table data without destroying the Pivot Table

We have a situation where we have a spreadsheet with a sheet data and the second sheet containing a pivot table. Some of our customers open their spreadsheets in read only or protected mode in Excel, which causes a notification that the pivot table cannot be updated upon opening it. Only the first sheet with the data is updated when we create the spreadsheet. The sheet with the pivot table is updated upon opening the spreadsheet (except in this case).

I've been looking everywhere and trying anything to remove the cache or the fields and get it to work. I want the pivot table to stay intact but not to present un-updated data in the pivot table sheet. We have a way to update the pivot table upon opening, but the problem has to do with the workbook being opened readonly or in protected mode which shows un-updated and wrong data in the pivot table.

This is what we use to make the sheet updatable and I've been trying to remove some things and to keep the workbook from displaying errors that a part is missing or something else, but with no succes:

 void SetPivotRefresh(Sheet sheet, bool sourceLocked)
 {
     try
     {
         List<PivotTableCacheDefinitionPart> pivotTableCacheDefinitionParts =
            _openXmlSpreadsheetDocument.WorkbookPart.PivotTableCacheDefinitionParts.Where(x =>
                x.PivotCacheDefinition.CacheSource.WorksheetSource.Name == sheet.CompleteName || x.PivotCacheDefinition.CacheSource.WorksheetSource.Sheet == sheet.CompleteName).ToList();

         foreach (PivotTableCacheDefinitionPart pivotTableCacheDefinition in pivotTableCacheDefinitionParts)
         {
             pivotTableCacheDefinition.PivotCacheDefinition.EnableRefresh = true;
             pivotTableCacheDefinition.PivotCacheDefinition.RefreshOnLoad = true;
             pivotTableCacheDefinition.PivotCacheDefinition.RecordCount = Convert.ToUInt32(sheet.RowCount);                                 

             if (!sourceLocked)
             {
                 WorksheetSource worksheetSource = pivotTableCacheDefinition.PivotCacheDefinition.PivotTableCacheDefinitionPart.PivotCacheDefinition.CacheSource.WorksheetSource;
                 // otherwise a share violation will be given and files built with OpenXML or Excel use these properties differently
                 worksheetSource.Sheet = sheet.CompleteName;
                 worksheetSource.Name = null;

                 string startingCellReference = sheet.ColumnDefinitions.FirstOrDefault()?.CellReference;
                 worksheetSource.Reference = startingCellReference + ":" + SpreadsheetHelper.ConvertColumnNumberToName(sheet.ColumnCount) + (sheet.RowCount + 1);
             }

             // Remove cache so that new information is updated
             pivotTableCacheDefinition.PivotTableCacheRecordsPart.PivotCacheRecords.RemoveAllChildren();
             pivotTableCacheDefinition.PivotTableCacheRecordsPart.PivotCacheRecords.Count = 0;
             pivotTableCacheDefinition.PivotCacheDefinition.Save();
         }
     }
     catch (Exception e)
     {
         Log.LogHandledException(e);
     }
 }

"sheet" is our own object which contains all the data that should go into an Excel sheet.

Get cell value bug

This document:

https://github.com/OfficeDev/open-xml-docs/blob/live/docs/how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md

Has this issue:

On this code:
if (theCell.InnerText.Length > 0)

It throws exception:
System.NullReferenceException: 'Object reference not set to an instance of an object.'

The exception happens when you want to find value of any cell in row A, if row A has been formatted to be a table, which means cells in row A will have name Column1, Column2 etc. and they will be filtering and sorting options.

Update documentation for latest versions

I'm the main maintainer on the OpenXML SDK and would like to get the docs updated to reflect the current state of things. This issue will be a (potentially growing) list of the items that we would like to update:

  • The documentation refers to specific versions - this is unnecessary as the version is not static nor is the content dependent on it (#158)
  • APIs have not been updated since 2.8.1 - should add APIs for at least v2.2.0 and v3.0.0 (it'll be released next month) (#156)
  • New samples are available at https://github.com/dotnet/Open-XML-SDK/tree/main/samples and should be migrated here
    • AnimatedModel3DExample
    • DocumentTaskExample
    • IsolatedStorageExceptionWorkaround
    • Linq
    • NamedSheetView
    • PowerPointModernCommentSample
    • RichData
    • SunburstChartExample
    • SVGExample
    • ThreadedCommentExample
  • Samples use VB and CS but are all inline and should be moved to actual test projects, be runnable, and shown in docfx tabs #163
  • Updated/new topics:
    • IFeatureCollection usage #179
    • LINQ support
    • Migration to v3 #178
  • Update getting started related steps (no longer need to "install" SDK - update to account for NuGet packages and dotnet CLI) #171
  • Reorganize doc file structure so that they match the toc #169
  • references to ISO/IEC 29500:2008 should be updated to 2016, including one reference to ISO/IEC2900:2008 (missing "5")
  • there are references and procedures for Visual Studio 2008
  • remove references to the SDK 1.0
  • completely revamp the What's New in the Open XML SDK topic #172
  • Documentation section in SDK Readme still mentions SDK 2.5
  • Fix broken samples

Sample Code no longer works for editing Word Document File.

The sample code and explanation provided in the documentation does not work for editing Word Document. It leaves the document in unreadable and incorrect format and the file does not open in MS Word.

The below sample code provided on StackOverflow, although inefficient, seems to work with some catches.

using ( WordprocessingDocument doc =
                    WordprocessingDocument.Open(@"yourpath\testdocument.docx", true))
            {
                var body = doc.MainDocumentPart.Document.Body;
                var paras = body.Elements<Paragraph>();

                foreach (var para in paras)
                {
                    foreach (var run in para.Elements<Run>())
                    {
                        foreach (var text in run.Elements<Text>())
                        {
                            if (text.Text.Contains("text-to-replace"))
                            {
                                text.Text = text.Text.Replace("text-to-replace", "replaced-text");
                            }
                        }
                    }
                }
            }
        }

Arabic text replacement issue - special characters in different order

Hi,

I Have a PPT template with Texts. I am just replacing text with Arabic text (It is a combination of Arabic and special characters) from c#. But it PPT it is showing in reverse order. The same if I copy-paste from notepad or another editor from visual studio code is working fine.

From code
image

Copy-paste from other editor

image

Code snippet

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Presentation;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
using Newtonsoft.Json;
using DocumentFormat.OpenXml.Drawing;

namespace SamplePPT
{
class Program
{
static void Main(string[] args)
{
try
{
byte[] pptBytes = File.ReadAllBytes(@"ProfileReportTemplate-ar.pptx");

            using (FileStream fileStream = new FileStream("ProfileReport", FileMode.Create))
            {
                fileStream.Write(pptBytes, 0, pptBytes.Length);

                using (PresentationDocument presentationDocument = PresentationDocument.Open(fileStream, true, new OpenSettings() { AutoSave = true }))
                {
                    PresentationPart presentationPart = presentationDocument.PresentationPart;
                    Presentation presentation = presentationPart.Presentation;

                    int slideIndex = 1;
                    OpenXmlElementList slideIds = presentation.SlideIdList.ChildElements;
                    SlidePart slidePart = (SlidePart)presentationPart.GetPartById((slideIds[slideIndex] as SlideId).RelationshipId);

                    slideIds = presentation.SlideIdList.ChildElements;
                    slidePart = (SlidePart)presentationPart.GetPartById((slideIds[slideIndex] as SlideId).RelationshipId);

                    if (slideIndex < slideIds.Count)
                    {

                        //Replacing the Master Text
                        foreach (DocumentFormat.OpenXml.Drawing.Paragraph paragraph in slidePart.Slide.Descendants<DocumentFormat.OpenXml.Drawing.Paragraph>())
                        {
                            foreach (DocumentFormat.OpenXml.Drawing.Text text in paragraph.Descendants<DocumentFormat.OpenXml.Drawing.Text>())
                            {
                                if (text.Text == "@@Program1")
                                {
                                    text.Text = "تم قبوله" + " - " + "دبلوم المسرعات الحكومية - مدير إدارة أو رئيس قسم" + " (" + "دفعة" + " " + "4" + ")";
                                }
                                else
                                {
                                    text.Text = string.Empty;
                                }
                            }
                        }
                    }

                    presentationDocument.SaveAs(@"ProfileReportTemplate-ar-updated.pptx");
                }
            }

            Console.Read();
        }
        catch (Exception ex)
        {

        }
    }
}

}

Can anyone suggest this?

Thanks in advance.

Example code produce invalid format

I'm trying your code example "CreateSpreadsheetWorkbook" for generating a simple spreadsheet and work fine (See "Text.xslx" attached). But when calling "InsertChartInSpreadsheet", the file is no more valid!

Test.xlsx

Can't read opened .docx document

I get "cannot access the file because it is being used by another process" exception when trying to WordprocessingDocument.Open(filepath,false);, althrough I can open it in other programs (like LibreOffice) in readonly mode.

Language dropdown

Could you add a language dropdown menu so that C# and VB snippets won't show up at the same time?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.