Quantcast
Channel: Open XML Format SDK forum
Viewing all 1288 articles
Browse latest View live

Is there a "Reset Slide" method for presentations in OpenXML SDK 2.5?

$
0
0
Hello, 

I am relatively new to C# and OpenXML.  I'm trying to use OpenXML to fix a very specific issue I'm having.  I have thousands of PowerPoint slides that are generated by Nintex DrawLoop pulling content and data from Salesforce.  Once Nintex generates the slides, they must be manually opened and the "Reset Slide" option on the context menu must be executed to apply the formatting of the Master Slide/Layout.  I have been unable to find a way to automate this step through VBA or Interopt.  I'm hoping I can accomplish this through OpenXML but so far my searching has not turned anything up.

Finding a way to automate this one manual step would be a huge help to me.  The menu option can be found when you right click a slide in the slide selector.  The menu option can also be found on the ribbon under Home|Slides|Reset

Thanks for your help.

Imran

VB.Net Code Mail merge using Open XML

$
0
0

Hi,

I am working on Mail merge with open XML.

I have

Word template with placeholders(.dotx)

Datasource to fill data in placeholders(sql or csv or txt)- 10 records

Destination file(.docx)

How to take data from datasource and fill it in placeholders and generate 10 files(.docx) using mailmerge  in VB.net.

Thanks in Advance.

Set text in docx bold by tag

$
0
0
When I need to do line folding in docx I use <w:br/>. Can I do something like this for bold text by means of tag?

UpgradeDocumentFormat.OpenXml from Version 2.5.5631.0 to 2.8.1

$
0
0

Hi, I am trying to upgrade DocumentFormat.OpenXml from 2.5 to latest stable version.

After NuGet latest version of Document Format Open XML my code is showing errors like the following.

SeverityCode DescriptionProjectFileLineSuppression State
ErrorCS0012 The type 'OpenXmlPart' is defined in an assembly that is not referenced. You must add a reference to assembly 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.GCMS.TemplatesC:\GIT\ReporterSuite\vip\GCMS.Templates\Excel\SpreadsheetWriter.cs124Active

For the following line line of code (the error applies to the second line)

            var workbookPart = sDoc.WorkbookPart;
            var wXDoc = workbookPart.GetXDocument();

I can't find my advice anywhere so some advice or help gratefully received.

Thanks:-)

Not able to implement Open XML SAX type approach in c#

$
0
0

My requirement is to export huge records with rows equal to 5 lakhs. I was using OpenXml approach like this :


 public void ExportCheck(DataSet ds, string destination)
        {
            using (var workbook = SpreadsheetDocument.Create(destination, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook))
            {                        
                var workbookPart = workbook.AddWorkbookPart();

                workbook.WorkbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();

                workbook.WorkbookPart.Workbook.Sheets = new DocumentFormat.OpenXml.Spreadsheet.Sheets();
               
                foreach (System.Data.DataTable table in ds.Tables)
                {
                    var sheetPart = workbook.WorkbookPart.AddNewPart<WorksheetPart>();
                    var sheetData = new DocumentFormat.OpenXml.Spreadsheet.SheetData();
                    
                    sheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(sheetData);                  
                    
                    DocumentFormat.OpenXml.Spreadsheet.Sheets sheets = workbook.WorkbookPart.Workbook.GetFirstChild<DocumentFormat.OpenXml.Spreadsheet.Sheets>();
                    string relationshipId = workbook.WorkbookPart.GetIdOfPart(sheetPart);
                    
                    uint sheetId = 1;
                    if (sheets.Elements<DocumentFormat.OpenXml.Spreadsheet.Sheet>().Count() > 0)
                    {
                        sheetId = sheets.Elements<DocumentFormat.OpenXml.Spreadsheet.Sheet>().Select(s => s.SheetId.Value).Max() + 1;
                    }

                    DocumentFormat.OpenXml.Spreadsheet.Sheet sheet = new DocumentFormat.OpenXml.Spreadsheet.Sheet() { Id = relationshipId, SheetId = sheetId, Name = table.TableName };
                    sheets.Append(sheet);               

                    DocumentFormat.OpenXml.Spreadsheet.Row emptyRow = new DocumentFormat.OpenXml.Spreadsheet.Row();

                     DocumentFormat.OpenXml.Spreadsheet.Row colRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
                    
                    List<DataColumn> columns = new List<DataColumn>();
                    
                    foreach (System.Data.DataColumn column in table.Columns)
                    {
                        columns.Add(column);
                        
                        DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
                        cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
                        cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue("<b>"+ column.ColumnName + "</b>");                      

                        colRow.AppendChild(cell);                        
                    }

                    sheetData.AppendChild(colRow);
                    string valueN;
                    foreach (System.Data.DataRow dsrow in table.Rows)
                    {
                        
                        DocumentFormat.OpenXml.Spreadsheet.Row newRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
                        foreach (DataColumn col in columns)
                        {
                            DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
                            cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;

                            if (col.DataType.Equals(typeof(byte[])) == true)
                            {
                                 valueN = ConvertByteArraytoInteger(dsrow[col.ColumnName]).ToString();
                                
                                cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(valueN);
                            }
                            else
                            {
                                cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(dsrow[col].ToString()); //
                            }
                            newRow.AppendChild(cell);
                        }

                        sheetData.AppendChild(newRow);
                    }
               
                 }
            }
        }

        

But now i have requirements in which data to be exported can be up to 10 lakh records with substantial number of columns. So i had to implement OpenXml Sax type approach as DOM approach is bit slow and memory consuming in case of large data.

I couldn't find any helpful link which shows me how to use that approach and convert data table/data set to excel. In most link they are using existing spreadsheet to create new excel. Can anyone provide changes to be made to above code to implement SAX approach or any link regarding the same.

Any help is deeply appreciated
Thanks

ChartEx data using OpenXML SDK

$
0
0

Hi, I am currently trying to get chart data for charts of type chartEx but am not able to find the chartSpace with OpenXML SDK 2.5 and 2.9. Can you tell me if those are not supported by the SDK and how to go about fetching the entire data as the charts of chartEx type are exposed in chartParts.

Looking to convert this VBA in Open XML SDK - looking for pointers or links

$
0
0

Looking for help converting this to open XML code.

Sample document -

open word Write 2 dummy paragraph Ctrl+A Layout tab -> click Columns ->choose TWO Select this para and then run the below macro. I want to achieve the same thing using Open XML.

Basically trying to copy a paragraph with formatting into a target document (or content control) while preserving the formatting.

Sub test43()
    Selection.Copy
    Selection.PasteAndFormat (wdFormatOriginalFormatting)
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type <> wdPrintView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveDocument.Range(Start:=Selection.Start, End:=Selection.Start). _
        InsertBreak Type:=wdSectionBreakContinuous
    Selection.Start = Selection.Start + 1
    ActiveDocument.Range(Start:=Selection.End, End:=Selection.End).InsertBreak _
         Type:=wdSectionBreakContinuous
    With Selection.PageSetup.TextColumns
        .SetCount NumColumns:=2
        .EvenlySpaced = True
        .LineBetween = False
       End With
End Sub


Need help to render text with following style definition

$
0
0

I have following style definition.

<w:style w:type="paragraph" w:styleId="Heading2"><w:name w:val="heading 2"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:link w:val="Heading2Char"/><w:uiPriority w:val="99"/><w:qFormat/><w:pPr><w:keepNext/><w:outlineLvl w:val="1"/></w:pPr><w:rPr><w:rFonts w:ascii="SW10BP" w:hAnsi="SW10BP" w:cs="SW10BP"/><w:sz w:val="24"/><w:szCs w:val="24"/></w:rPr></w:style><w:style w:type="character" w:customStyle="1" w:styleId="Heading2Char"><w:name w:val="Heading 2 Char"/><w:basedOn w:val="DefaultParagraphFont"/><w:link w:val="Heading2"/><w:uiPriority w:val="99"/><w:rPr><w:rFonts w:ascii="Cambria" w:hAnsi="Cambria" w:cs="Cambria"/><w:b/><w:bCs/><w:i/><w:iCs/><w:sz w:val="28"/><w:szCs w:val="28"/><w:lang w:val="x-none" w:eastAsia="en-US"/></w:rPr></w:style>

And following paragraph definition

<w:p w:rsidR="00964377" w:rsidRDefault="00C64928"><w:pPr><w:pStyle w:val="Heading2"/><w:ind w:left="720" w:hanging="720"/><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/><w:b/><w:bCs/><w:sz w:val="20"/><w:szCs w:val="20"/></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/><w:b/><w:bCs/><w:sz w:val="20"/><w:szCs w:val="20"/></w:rPr><w:t>1.</w:t></w:r><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/><w:b/><w:bCs/><w:sz w:val="20"/><w:szCs w:val="20"/></w:rPr><w:tab/><w:t>DEFINITIONS</w:t></w:r></w:p>

Word renders it non-Italic form, while the linked character style has the Italic property. How can I decide not to apply Italic here.




how get placehold rectange (offset and extent)

$
0
0
where  offset and  extent of a placeholder   in powerpoint ?  

Writing to running Excel Application

$
0
0

Is it possible to write to running instance of Excel app with Open XML?

In a similar way that you can do with interop via (Application) Marshal.GetActiveObject("Excel.Application")

Thank you

Apply column filter value through the AutoFilter option in the Excel is not working - C#

$
0
0

Description : 
In C# application, the AutoFilter drop-down arrows are visible but no rows are currently filtered with value (all rows are visible).

unable to apply the value in the Filter. For example if i try to apply value "aaa" in the third column - in the result data filter is not applying correctly. it displays the all data without filtering.

I set SheetProperties.FilterMode as true still filter is not applied


Unable to upload the images as my account is not yet verified and please verify my account to send the images.

please find the code snippet below.   

static void ApplyFilterValue(string fileName)

        {
          using (SpreadsheetDocument spreadsheetDocument =
           SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook))
            {              
                SheetData sheetData = new SheetData();
                Row titleRow = new Row { RowIndex = (UInt32)1 };

                titleRow.AppendChild(CreateTextCell("A", "Entity Name", 1));
                titleRow.AppendChild(CreateTextCell("B", "Event Name", 1));
                titleRow.AppendChild(CreateTextCell("C", "Attribute Name", 1));
                titleRow.AppendChild(CreateTextCell("D", "Object Name", 1));
                titleRow.AppendChild(CreateTextCell("E", "Type Name", 1));
                titleRow.AppendChild(CreateTextCell("F", "Tab Name", 1));
                titleRow.AppendChild(CreateTextCell("G", "Section Name", 1));

                // Append Row to SheetData
                sheetData.AppendChild(titleRow);
                string[,] ConversionReportItems = new string[,] { {"aaa","bbb","ccc","ddd","eee","fff","ggg" },
                                                                { "aaa","bbb","aaa","ddd","eee","fff","ggg" },
                                                                { "aaa","bbb","ccc","ddd","eee","fff","ggg" },
                                                                { "BBB","bbb","aaa","ddd","eee","fff","ggg" },
                                                                { "aaa","bbb","ccc","ddd","eee","fff","ggg" },
                                                                { "aaa","bbb","aaa","ddd","eee","fff","ggg" },
                                                                { "aaa","bbb","ccc","ddd","eee","fff","ggg" } };
                for (int i = 0; i < 7; i++)
                {
                    Row row = new Row { RowIndex = (UInt32)i + 2 };

                    row.AppendChild(CreateTextCell("A", ConversionReportItems[i, 0], i + 2));
                    row.AppendChild(CreateTextCell("B", ConversionReportItems[i, 1], i + 2));
                    row.AppendChild(CreateTextCell("C", ConversionReportItems[i, 2], i + 2));
                    row.AppendChild(CreateTextCell("D", ConversionReportItems[i, 3], i + 2));
                    row.AppendChild(CreateTextCell("E", ConversionReportItems[i, 4], i + 2));
                    row.AppendChild(CreateTextCell("F", ConversionReportItems[i, 5], i + 2));
                    row.AppendChild(CreateTextCell("G", ConversionReportItems[i, 6], i + 2));
                    row.Hidden = false;
                    // Append Row to SheetData
                    sheetData.AppendChild(row);
                }

                // Add a WorkbookPart to the document.
                WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
                workbookpart.Workbook = new Workbook();

                // Set the AutoFilter property to a range that is the size of the data
                // within the worksheet
                AutoFilter autoFilter1 = new AutoFilter() { Reference = "A1:G9"};

                FilterColumn filterColumn1 = new FilterColumn() {ColumnId = 2 };

                Filters filters1 = new Filters() { };
                Filter filter1 = new Filter() { Val = "aaa" };

                filters1.Append(filter1);                           

                filterColumn1.Append(filters1);

              autoFilter1.Append(filterColumn1);

                Worksheet sheet1 = new Worksheet();

                sheet1.Append(sheetData);
                sheet1.Append(autoFilter1);

                // Add a WorksheetPart to the WorkbookPart.
                WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
                worksheetPart.Worksheet = sheet1;

                worksheetPart.Worksheet.Save();

                // Add Sheets to the Workbook.
                Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());

                // Append a new worksheet and associate it with the workbook.
                Sheet sheet = new Sheet()
                {
                    Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
                    SheetId = 1,
                    Name = "Conversion Report"
                };

                sheets.Append(sheet);

                // Close the document.
                spreadsheetDocument.Close();
            }
        }

                                                                                                                                                              

Embedded Font not working in Powerpoint

$
0
0

Hi,

our web-app generates pptx files with the openxml-sdk and we use custom fonts (Roboto). The pptx files contains roboto as embedded font, textfields and metafiles(emf).

The textfields working well with the custom fonts, but the metafiles display text in arial. Only if i ungroup the metafile and convert into microsoft office drawing object the embedded font is used. The metafile is created on serverside with roboto font.

The question is: How can i ungroup the metafile before the file is saved and transmitted to the client? Or what can i do, that powerpoint uses the embedded font also for the includes metafile?

Thank you.

Office 2013 pagebookmark not updating in TOC

$
0
0

Hi

So we are using openxml and c# to create a TOC . We have added pagebookmarks PageREF for that and when we are trying to do refresh all where we are updating the fields ultimately, its not giving us the correct sequence of pages.Sometimes all are coming as 1 or all are coming as 3.

Although on word 2010 , it works very well.

Export large set of variable data to new xlsx using OpenXML SAX approach

$
0
0

Hi, Everyone

I hope someone can help me I'm at my wits end!

Scenario:

Export large set of data from Datatable (i.e. List of clients with some related details) - the Datatable may be different on every export.  This may range from a couple of hundred to a couple of million rows of data.

I need to be able to create a new blank .xlsx file, export the details if the details span more than one sheet append extra sheets until the whole datatable is exported.

I cannot use the existing template approach with is used in 100% of example code in all SAX approaches with OpenXML and after days of trying I just cannot anymore!

Does anyone know of references that may guide me in the right direction here?

How to change the font size of a numbered list

$
0
0

Hello,

I am using C# and I am able to create a numbered list and add paragraphs to it just fine.  I am reading in from a template and then outputting to a new file.  For some reason, the default font size on the new file is 10 when I output paragraphs to it.  Also, the numbered list numbers are size 10.  I want both to be size 12.  How do I do this?


OpenXml SDK- How to uniquely identify a paragraph in a word document

$
0
0

I need to extract paragraphs based on some unique ids or something that can identify/differentiate each paragraph in a 50- 60 pages word document (using TX Text Editor to load it) . I will tag these unique IDs to a list box or some other list control and on-click of the list box item, go to that specific paragraph and highlight it. I thought w:paraID is unique but it is null and not for development purpose. There should be some custom hack where in i can add something.

Right now i convert the TxText Editor loaded content to docx -> wordprocessingML and trying to figure out how to extract certain paragraphs using some unique ids or style. The Content of the Paragraph will not be known, only some mapping between the listitem and Docx will be there to highlight the entire paragraph.

Regards, Jasbir

C#, Open XML and removing a sheet from an xlsx

$
0
0

I try to remove a sheet from an Excel file and I have tried a lots of source from Internet but I always get the same result: unreadable content.

The link of the last one: https://blogs.msdn.microsoft.com/vsod/2010/02/05/how-to-delete-a-worksheet-from-excel-using-open-xml-sdk-2-0/

I also tried this:

 Sheet sheet = workbook.WorkbookPart.Workbook.Descendants<Sheet>().First(s => s.Name.Equals(sheetName));
 sheet.Remove();
 workbook.WorkbookPart.Workbook.Save();

+ sheet.RemoveAllChildren()

But the file is always corrupt.

Programmatically update Word Link/Embedded Files Source Location

$
0
0

Hi I'm not sure if I posted this in the right forum, so please feel free to point me in the right direction.
We are in the middle of migrating thousands of Word and Excel (Office 2010) files from Novel servers to Windows servers.

The issue we have is that the vast majority of this Word documents have link or embedded Excel files.
We need to update the source file location in the Word files and manually doing so is out of the question, this will be an impossible task.

I have search and found .NET code that will modify the source location of link/embedded files in Word.

Is there a way to accomplish this automatically or with minimum manual intervention?
Is there any sample code that I can modify to accomplish this?
I'm using VS2012 and VB (I know this is not the best, I should use C#).
Any advice will be greatly appreciated

Gil


Using Universal Windows app (ver:10.0) not able edit bookmarks in word documents

$
0
0

I am build a Universal Windows application(UWP) which needs to add text to the bookmarks in a Microsoft Word Document which is on a network folder. I need help to understand how to create this app.

When I tried using DocumentFormat.OpenXml library I was getting "File not Found" error for the below code.

using(WordprocessingDocument wordDoc =WordprocessingDocument.Open("C:\\Users\\Public\\Desktop\\Doc1.docx",true)){}


number format is not getting applied

$
0
0
//  Add a new Excel Cell to our Row 
            Cell cell = new Cell() { CellReference = cellReference };
            CellValue cellValue = new CellValue();
            CellFormat cellfrmt = new CellFormat();
            cellfrmt.NumberFormatId =2;
            cellValue.Text = cellStringValue;
            cell.Append(cellValue);
            cell.Append(cellfrmt);
            excelRow.Append(cell);
Viewing all 1288 articles
Browse latest View live


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