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

embedding object (jepg, png and pdf etc) in word document by openXML.

$
0
0

Hi All, 

  1.        In Open XML, there are basically 2 different classes provided to embed any file or object in Open XML Document.
    1.        EmbeddedPackagePart
    2.       EmbeddedObjectPart
  2.        EmbeddedPackagePart is used to embed Open XML Packages inside document, for e.g. docx, xlsx files.
  3.        Using EmbeddedObjectPart, we can add any file as an Object inside document.

Scenarios:

Embed Open XML package inside document

In this case, we can use EmbeddedPackagePart class and use feeddata method of same class, which will create a package file (extension: .package). And store it into embeddings folder under document folder of Open XML package.

As package is an Open XML package, OpenXML SDK easily can cache it and store it inside document package.

MSDN Code Ref. https://msdn.microsoft.com/en-us/library/ee355229(v=office.12).aspx

Embed Object inside document

In this case, we use EmbeddedObjectPart with application/vnd.openxmlformats-officedocument.oleObject content type. When we use feeddata method of this class, it will create a Bin file (extension: .bin) and store it in embeddings folder.

Now issue is Open XML itself not able to create bin cache file. It’s not get linked with Object tag in document, as Microsoft Office does not recognized bin file created by Open XML SDK.

So we use Open XML Productivity Tool shipped with Open XML SDK from MSDN ( https://www.microsoft.com/en-us/download/details.aspx?id=30425 ). And use that tool to regenerate code of Docx file, which have an embedded Object using Microsoft word.

In code we have found, a Base 64 String, which is used to generate object. When we convert that Base 64 String to check file type, we have found that file signature (Magic Number: https://en.wikipedia.org/wiki/Magic_number_(programming) ) of Base 64 was related to Old file extensions e.g. Doc, xls.

List of file signatures : https://en.wikipedia.org/wiki/List_of_file_signatures

Magic Number of File Extensions : http://asecuritysite.com/forensics/magic

Can someone help me on this?

Regards, 

Manish


manish


space inside Internal hyperlink fieldcode text

$
0
0
Hello,

We have a application where we have to count the length of the fieldcode text in word document for which we are counting the text inside the InstrText tag which is working fine so far. But we are not able to calculate the fieldcode text of the internal hyperlink field. we using below code snippet to manually build instrText of the hyperlink field.

string HyperlinkFC = string.Empty;
if (element.Attributes().Any(a => a.Name.LocalName == “anchor”))
{
string s = @”HYPERLINK \l”; 
HyperlinkFC = string.Format(” {0} \”{1}\” “, s, element.Attribute(W.anchor).Value);
}
fieldCodeText.Append(HyperlinkFC);

Above code is working fine for some cases like below:
{HYPERLINK \l “_Toc165886552”}

But it is failing for some cases where there is a trailing and leading white space inside the curly braces of Hyperlink fieldcode in the begining and end as below

{ HYPERLINK \l “_Toc165886552” }

It is giving 2 characters length difference than expected.

Any help will be truly appreiciated!!

Thanks

Write with position

$
0
0

Hi,

Further to this thread, is there any demonstration to also put RowID, ColumnID, to InsertText event?


Many Thanks & Best Regards, Hua Min

Creating an Excel File-Making first line bold not working.

$
0
0

Hello,

I'm new to Open XML.

I'm trying to create an Excel file using a text input file.

I'm just trying to Bold the top row, but I don't seem to be having any success using a stylesheet.

Using VB.NET

My Stylesheet contains 2 fonts.

The first, size is 13, font is bold.

The 2nd, size is 13, font is not bold.

If I'm in the first row, I want to use the first font, any other rows I want to use the 2nd font.

The data gets written to the spreadsheet but it will only use the first font definition.

 

'Read a line from the text file

  Dim rw As New Row()
    For i = 0 To wordsinline - 1
      a = adata(i)
      Dim c0 As Cell = New Cell
      c0.CellValue = New CellValue(a)
      c0.DataType = New EnumValue(Of CellValues)(CellValues.String)
        If counter = 1 Then
               c0.StyleIndex = 0 'bold
             Else
                c0.StyleIndex = 1 'not bold
             End If
             rw.Append(c0)
             cellindex = cellindex + 1
            Next
         sheet_data.Append(rw)
         counter = counter + 1

'Read next line in the file..
My Stylesheet

Private Function GenerateStyleSheet() As Stylesheet

        Dim font0 As New Font()
        Dim font1 As New Font()
        Dim bold0 As New Bold()
        Dim bold1 As New Bold()
        Dim fontsz0 As New FontSize()
        Dim fontsz1 As New FontSize()
        Dim fonts0 As New Fonts()

        'do font0
        bold0.Val = True
        fontsz0.Val = 14

        bold1.Val = False
        fontsz1.Val = 13

        font0.Append(bold0)
        font0.Append(fontsz0)

        font1.Append(fontsz1)
        font1.Append(bold1)

        fonts0.Append(font0)
        fonts0.Append(font1)


        'Fills
        Dim ofills As New Fills()
        Dim ofill As New Fill()
        ofills.Append(ofill)

        Dim bords As New Borders()
        Dim bord As New Border()
        bords.Append(bord)

        Dim cf0 As New CellFormat()
        With cf0
            .FormatId = 0
            .FillId = 0
            .FontId = 1
            .BorderId = 0
        End With

        Dim cf1 As New CellFormat(New Alignment() With {.Horizontal = HorizontalAlignmentValues.Center, .Vertical = VerticalAlignmentValues.Center})
        Dim cfmts As New CellFormats
        cfmts.Append(cf0)
        cfmts.Append(cf1)

        Dim sty As New Stylesheet()
        sty.Append(fonts0)
        sty.Append(ofills)
        sty.Append(bords)
        sty.Append(cfmts)
        Return sty
    End Function
Any assistance appreciated.. thx


OpenXML - Unable to find the .glox file to create custom Smart Art for MS office PowerPoint

$
0
0

Hi ,

I want to create custom Smart Art for PowerPoint 2013.Got the OpenXMLEditor Extension for Visual Studio installed to serve the purpose. To customize it a .glox file is required as mentioned in [https://msdn.microsoft.com/en-us/library/office/gg583880(v=office.14).aspx] . But it is missing from the designated folder in my installation.

Where can i get the .glox file ?

Is there any support available to customize using OpenXML for Office 2013? 

Continuous list numbering issue in Doc

$
0
0
Hi, 

we have a document where it's listnum is continuously incrementing in the next page as well though it should not.

is there a solution for this?

Thanks,
Manohar

Better way to work with XML file

$
0
0
Hi,

Further to this thread, it is slow to use InsertText to each time write to one cell with values. Must we ensure we each time do write to one whole Excel row to have better performance, for writing to an OPENXML file?



Many Thanks & Best Regards, Hua Min

Slow process

$
0
0
Hi,
Further to this, as I'm using the same codes to write Excel file, one problem is, it is still slow to write to relevant Excel file. Any advice to this?

Many Thanks & Best Regards, Hua Min


Productivity Tool usability

$
0
0

The Open XML SDK 2.5 Productivity Tool does some amazing things for me, but it would be even better if there could be some way to automatically fill in the Browse Files to Compare dialog box, such as with the last files opened. I could probably add this highly useful feature if somebody knows where the source code is.

What I tried:

  1. Google search for: Open XML SDK Productivity Tool command line
  2. I used the Spy++ program that comes with Visual Studio. It only recognizes the dialog box, not the dialog box controls.
  3. I wrote a program to find the dialog using EnumWindows(). I can find the dialog and move the control focus by sending it tab characters, but EnumChildWindows() doesn't find the dialog controls, and sending keystrokes to the dialog doesn't fill in the dialog controls.
  4. Posted this question to
    https://social.msdn.microsoft.com/Forums/office/en-US/fe725086-8e16-4a9e-8419-3aaec36aa1cd/productivity-tool-usability?forum=oxmlsdk#438a8133-e55c-4b61-99e5-d1c9cc5a994a
    and
    https://github.com/OfficeDev/Open-XML-SDK/issues/103

In both cases I was told to post somewhere else. It would be great to not get the runaround this time.

Howard Rubin

How to show data and graph in Power Point Slides by OpenXML library

$
0
0

is it possible to show data and graph in Power Point Slides by OpenXML library ?

in each slide there will be two set of data and their corresponding graph. i may have 2/3 slides which will be showing one after one after a specific time interval.

please give me some hints to achieve it by OpenXML library.

i am interested to use OpenXML library because when my application will be running on a pc where MS office suite may not be available.

looking for guidance. thanks

Productivity Tool usability

$
0
0

The Open XML SDK 2.5 Productivity Tool does some amazing things for me, but it would be even better if there could be some way to automatically fill in the Browse Files to Compare dialog box, such as with the last files opened.

What I tried:

  1. Google search for: Open XML SDK Productivity Tool command line
  2. I used the Spy++ program that comes with Visual Studio. It only recognizes the dialog box, not the dialog box controls.
  3. I posted a question to github/OfficeDev/Open-XML-SDK
  4. I wrote the below program to find the dialog using EnumWindows(). I can find the dialog and move the control focus by sending it tab characters, but EnumChildWindows() doesn't find the dialog controls, and sending keystrokes to the dialog doesn't fill in the dialog controls.

Howard Rubin

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

int _tmain(int argc, _TCHAR* argv[]) {
    EnumWindows(EnumWindowsProc, NULL);
    return 0;
}

using namespace std;

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {
    wcout << hwnd << std::endl;
    return TRUE;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
    wchar_t title[1000];
    GetWindowText(hwnd, title, sizeof(title)-1);
    if (!wcscmp(L"Browse Files to Compare", title)) {
            wcout << "Window title: " << title << endl;
        EnumChildWindows(hwnd, EnumChildProc, NULL);

        for (int i = 0; i < 2; ++i) {
            SendMessage(hwnd, WM_KEYDOWN, VK_TAB, 0);
            SendMessage(hwnd, WM_KEYUP, VK_TAB, 0);
        }
        //SendMessage(hwnd, WM_CLOSE, NULL, NULL);
    }
    return TRUE;
}



Finding the enumeration of a paragraph

$
0
0

Hello together,

I have a rather tricky problem. I need to find the enumeration symbol in front of a paragraph, like

1) This is the first line

2) this is the second line

In this case the 1) and 2) is not contained within the paragraph itself, but hidden somewhere else.

Is there any way to get this information?

Kind regards,

Simon

Problem to event

$
0
0
Hi,
Further to this, how about that I DID NOT read from one Text file within InsertCellInWorksheet, by which I was to write to one cell each time?

Many Thanks & Best Regards, Hua Min

Unable to adjust paragraph alignment

$
0
0

So I'm trying to open a word document and replace a block of text in the bottom right side of the first page with a picture. I am able to replace the image, but it is not positioned the way I want it to be. Changing the frame properties/paragraph properties doesn't seem to help. Is there another approach that I seem to be missing?

    if (text.Text == "text match")
                {
                  paragraph.RemoveAllChildren();
                  ParagraphProperties paraProp = new ParagraphProperties
                  {
                    KeepNext = new KeepNext(),
                    FrameProperties = new FrameProperties
                    {
                      HeightType = HeightRuleValues.Auto,
                      VerticalPosition = VerticalAnchorValues.Page,
                      HorizontalPosition = HorizontalAnchorValues.Page,
                      XAlign = HorizontalAlignmentValues.Right,
                      YAlign = VerticalAlignmentValues.Bottom
                    }
                  };
                  paragraph.ParagraphProperties = paraProp;
                  paragraph.Append(new Run(element.CloneNode(true)));
                  break;
                }

Edit: I forgot to mention, this block is running in a large nested foreach loop iterating through every text in every run in every paragraph. In this context, paragraph is the current paragraph.


GroupShape instance as child element in GroupShape

$
0
0

Sorry for my English :)

My understanding is in PowerPoint there is only one level grouping - a group cannot be in a group, but looking at the source code classGroupShape

I see that GroupShape instance can have a GroupShape instance. Do I understand correctly or maybe this portion of Open XML not deal with PowerPoint?


Create RTF document

$
0
0

Hi All,

I want to create the RTF document using c#. I have used the OpenXml to create the office document docx. 

Is it possible to use same for RTF ?

Please share anyone knows anything regarding the RTF creation.

Thanks !

 

 

Requiring Install of Core

$
0
0
Starting with 2.8, the nuget package forces the install of a bunch of packages from (and including) Core.  I understand and support the fact that Core is supported.  However, why does someone who is not using Core required to install Core to use this package?  That is a lot of baggage if it is not required.

AlternativeFormatImportPart (AltChunk) and WordprocessingDocument in MemoryStream creates a corrupt file

$
0
0

Hi, I have a project where i need to add plain text as well as the content of small .docx files to a main .docx.
I have created a test case, and with the use of AlternativeFormatImportParti I can successfully perform the following code to add plain text in my files.

string chunkId = "D"+Regex.Replace(DateTime.Now.ToString(), @"[^\d]", "");

AlternativeFormatImportPart chunk = _mainDocPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.TextPlain, chunkId);

using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(text)))
{
	chunk.FeedData(memstream);
}

AltChunk altChunk = new AltChunk();
altChunk.Id = chunkId;

OpenXmlElement parent = placeHolder.Parent;
parent.InsertBefore(altChunk, placeHolder);

The problem is that in my actual environment I need to load WordprocessingDocument  from a memory stream.
It seems like when i do this the saved file cannot be opened by Word (Corrupt file)

I can add paragraphs and other stuff, but not AltChunck when I initiate the WordprocessingDocument as follows

var byteArrayWithFileFrom360 = ProcessFileHandler.GetFileContent(204735);

var wordDocMemoryStream = new MemoryStream();
wordDocMemoryStream.Write(byteArrayWithFileFrom360, 0, byteArrayWithFileFrom360.Length);

var myDoc = WordprocessingDocument.Open(wordDocMemoryStream, true);

 

Performance impact in Creation of Excel file with Huge data Records ( 1 lak records)

$
0
0

Hi

we are using the openxml  sdk in building the excel file at runtime which was consuming bit high memory with normal load of around 100 records and it takes close to 1 min - 3 min time intervals based on the load. Now we need to support the file generation with 1 lak records data and we see a huge spike in the memory and this is blocking the other operations.. 

is there any settings which can help us on file generation with less memory consumption even on huge data insertions into excel .

Thanks,

Manoj


Thanks, Manoj

XML declaration is repeated at the document

$
0
0

Hi,
   I am using c# open XML to write to excel. However, in the document. The XML declaration is repeated. What is the cause of this error and how to fix it?

<?xml version="1.0" encoding="utf-8" standalone="yes"?><x:worksheet
	xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac"
	xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><x:dimension ref="A1" /><x:sheetViews><x:sheetView tabSelected="1" workbookViewId="0" /><?xml version="1.0" encoding="utf-8" standalone="yes"?><x:worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><x:dimension ref="A1" /><x:sheetViews><x:sheetView tabSelected="1" workbookViewId="0" />


hon123456

Viewing all 1288 articles
Browse latest View live


Latest Images

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