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

How to read password protected XLSX file using Open XML

$
0
0

Hi,

How to read password protected XLSX file using Open XML, I do have the password.

I know lot of people have asked same question lot of times, but what i found that this question has been asked about two year back, so now whether any modification has been done in openXML to do the same.


Server Generated Word Doc will Validate but not Open

$
0
0

I've posted this question over on Stack Overflow but it's not getting a lot of traction. Hopefully I'll have better luck here. I'll leave the progression of my work on the problem there and just post the current details here as the code is rather lengthy.

I was trying to adapt this example to populate a Word template with data from a database on a server without Office installed (no Interop). I was told that that method is no longer valid due to a patent lawsuit. So I'm currently working from this example instead using the Open XML SDK 2.5.

What I'm trying to achieve is to be able to pull a template from the database and store the resultant populated document back into the database.

I can upload and download the template file itself and the downloaded template is still readable by Word. But when I try and populate the template with data and download the resultant document, I receive the following error when I try to open the document:

We're sorry. We can't open SimpleTest.docx because we found a problem with its contents.
Details: No error detail available

Converting to .zip and inspecting the contents, everything looks okay and the expected data has been placed in the correct place. I have even used the Open XML SDK 2.5 Productivity Tool and the generated .docx validates under Word 2007, 2010, and 2013.

Here is the code I'm using:

Protected Overrides Sub Execute()
    'Get the parameters and the template to be filled
    Dim params As CreateOfferingParams = Parameters
    Dim serverWorkSpace = Application.Current.CreateDataWorkspace()
    Dim offeringTemps = From sws In serverWorkSpace.aris_dbData.DocTemplates
                        Where sws.TemplateName.Contains("SimpleTest")
                        Select sws

    'Open the template and copy it into a local byte array
    Dim myTemplate As DocTemplate = offeringTemps.FirstOrDefault()
    Dim fileBuffer As Byte() = myTemplate.TemplateFile

    'Open the file stream in memory and create a document object from it
    'Must be done this way so stream is expandable
    Dim pkgStream As MemoryStream = New MemoryStream
    pkgStream.Write(fileBuffer, 0, fileBuffer.Length)

    Using docTemplate As WordprocessingDocument = WordprocessingDocument.Open(pkgStream, True)
        'Create XML string matching custom XML part
        'Extract the main part of the document and replace any custom XML
        Dim mainPart As MainDocumentPart = docTemplate.MainDocumentPart

        For Each part As CustomXmlPart In mainPart.CustomXmlParts
            Dim docStream As New MemoryStream
            Dim docWriter As XmlWriter = XmlTextWriter.Create(docStream)

            'Write the declaration, root element and our namespace
            docWriter.WriteStartDocument()
            docWriter.WriteStartElement("Offering", "http://www.mycompany.com")

            'Write in each data element
            For Each element In params.OfferingData
                docWriter.WriteElementString(element.Key, element.Value)
            Next

            'Close each of the tags and flush the stream
            docWriter.WriteEndElement()
            docWriter.WriteEndDocument()
            docWriter.Flush()

            'Rewind the stream and feed it to the custom XML part we are working on
            docStream.Seek(0, SeekOrigin.Begin)
            part.FeedData(docStream)

            'Rewind the package stream
            pkgStream.Position = 0

            'Copy the modified package into a new byte array
            Dim generatedOffering As Byte() = New Byte((pkgStream.Length) - 1) {}
            Dim i As Integer = 0
            Do While (i < pkgStream.Length)
                generatedOffering(i) = CType(pkgStream.ReadByte, Byte)
                i = (i + 1)
            Loop

            'Get the appropriate Quote entity so we have somewhere to store the newly generated file
            Dim quoteInfo = From sws In serverWorkSpace.aris_dbData.Quotes
                            Where sws.QuoteID = params.QuoteIDParam
                            Select sws

            Dim myQuote As Quote = quoteInfo.FirstOrDefault()

            'Store the file in the entity
            myQuote.QuoteOffering = generatedOffering

            'Save out the changes
            serverWorkSpace.aris_dbData.SaveChanges()
        Next
    End Using
End Sub

Here are Dropbox links to the template file and the generated .docx.

Can anyone see what I'm doing wrong?

SmartArts Types

$
0
0
How to add a private SmartArt Type beside the given ones (list, process, hierarchy, ...) to insert its individual layouts?

OpenXML: Finding and Manipulating Embedded Charts in a Word Doc

$
0
0

I'm very close on this.

I'm trying to create a function that will locate and update an embeded chart within a Word document.  Ultimately, the document will have sevral charts.

So far, my function can iterate through the document and find a chart (currently there is only one) and plug in some dummy info.  It works, however when the document is opened, I get a pop-up complaining that the document is corrupt.  I OK past that and a second pop-up asks me if I'd like to recover the document.  I OK that and the document then opens and the chart is updated, all as if nothing were wrong.

So it winds up OK, but my users are not going to be happy with the "corrupt file" messages.  When they're not happy, no one is happy.

Also, I'm looking for a methodology to find and update a specific chart.  Currently I iterate through the document, and if I had to I could live with that but I'd like to implement something a little less fragile.

I was looking at perhaps using the "Title" property on the chart and attempting to have the SDK search for that.  I'm a relative newbie to this SDK and can't seem to locate an example of that (or *ANYTHING* for that matter that attempts to find a specific chart in a document).

Here is my code so far.  It's just a prototype, so it is maufacturing data for the cells and allthough it is iterating through the document, there is no method yet to target a specific chart:

	private void updateChart( WordprocessingDocument doc )
	{
		string rid = null;

		Stream stream = null;


		foreach ( Paragraph p in doc.MainDocumentPart.Document.Body.Elements<Paragraph>( ) )
		{
			foreach ( Drawing d in p.Descendants<Drawing>( ) )
			{
				foreach ( ChartReference cr in d.Descendants<ChartReference>( ) )
				{
					rid = cr.Id.Value;

					ChartPart cp = ( ChartPart )doc.MainDocumentPart.Parts.Where( pt => pt.RelationshipId == rid ).FirstOrDefault( ).OpenXmlPart;

					foreach ( ExternalData ed in cp.ChartSpace.Elements< ExternalData >( ) )
					{
						string externalDataRID = ed.Id.Value;
						EmbeddedPackagePart epp = ( EmbeddedPackagePart )cp.Parts.Where( pt => pt.RelationshipId == ed.Id ).FirstOrDefault( ).OpenXmlPart;

						using ( Stream str = epp.GetStream( ) )
						{
							using ( MemoryStream ms = new MemoryStream( ) )
							{
								CopyStream( str, ms );
								using ( SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open( ms, true ) )
								{
									ss.Sheet ws = ( ss.Sheet )spreadsheetDoc.WorkbookPart.Workbook.Sheets.FirstOrDefault( );

									string sheetId = ws.Id;

									WorksheetPart wsp = ( WorksheetPart )spreadsheetDoc.WorkbookPart.Parts.Where( pt => pt.RelationshipId == sheetId ).FirstOrDefault( ).OpenXmlPart;
									ss.SheetData sd = wsp.Worksheet.Elements<ss.SheetData>( ).FirstOrDefault( );

									int ctr = 0;
									foreach ( ss.Row row in sd.Elements< ss.Row >( ) )
									{
										if ( ctr > 0 && ctr <= 6 )
										{
											ss.CellValue cv0 = row.Elements<ss.Cell>( ).ElementAt( 0 ).Elements<ss.CellValue>( ).FirstOrDefault( );
											cv0.Text = _monthsInRange[ ctr - 1 ].startDate.ToString( "MMM-yyyy" );

											ss.CellValue cv1 = row.Elements<ss.Cell>( ).ElementAt( 1 ).Elements<ss.CellValue>( ).FirstOrDefault( );
											cv1.Text = ( ctr * 10 ).ToString( );

											ss.CellValue cv2 = row.Elements<ss.Cell>( ).ElementAt( 2 ).Elements<ss.CellValue>( ).FirstOrDefault( );
											cv2.Text = ( ctr * 10 ).ToString( );

											ss.CellValue cv3 = row.Elements<ss.Cell>( ).ElementAt( 3 ).Elements<ss.CellValue>( ).FirstOrDefault( );
											cv3.Text = ( ctr * 10 ).ToString( );

											ss.CellValue cv4 = row.Elements<ss.Cell>( ).ElementAt( 4 ).Elements<ss.CellValue>( ).FirstOrDefault( );
											cv4.Text = ( ctr * 10 ).ToString( );

											ss.CellValue cv5 = row.Elements<ss.Cell>( ).ElementAt( 5 ).Elements<ss.CellValue>( ).FirstOrDefault( );
											cv5.Text = ( ctr * 10 ).ToString( );
										}++ctr;
									}
								}

								using ( Stream s = epp.GetStream( ) )
								{
									ms.WriteTo( s );
								}
							}
						}



						Chart chart = cp.ChartSpace.Elements<Chart>( ).First( );
						Bar3DChart bc = chart.Descendants<DocumentFormat.OpenXml.Drawing.Charts.Bar3DChart>( ).FirstOrDefault( );

						if ( bc != null )
						{
							foreach( BarChartSeries bcs in bc.Elements<BarChartSeries>( ) )
							{
								CategoryAxisData cad = bcs.Descendants<CategoryAxisData>( ).FirstOrDefault( );

								StringReference sr = cad.Descendants<StringReference>( ).FirstOrDefault( );
								StringCache sc = sr.Descendants<StringCache>( ).First( );
								int ctr = 0;
								foreach ( StringPoint sp in sc.Descendants<StringPoint>( ) )
								{
									NumericValue nv = sp.Descendants<NumericValue>( ).First( );
									nv.Text = _monthsInRange[ ctr ].startDate.ToString( "MMM-yyyy" );++ctr;
								}


								foreach ( Values values in bcs.Descendants<Values>( ) )
								{
									NumberingCache nc = values.Descendants<NumberingCache>( ).First( );

									NumericValue nv1 = nc.Elements<NumericPoint>( ).ElementAt( 0 ).Elements<NumericValue>( ).FirstOrDefault( );
									nv1.Text = "10";

									NumericValue nv2 = nc.Elements<NumericPoint>( ).ElementAt( 1 ).Elements<NumericValue>( ).FirstOrDefault( );
									nv2.Text = "20";

									NumericValue nv3 = nc.Elements<NumericPoint>( ).ElementAt( 2 ).Elements<NumericValue>( ).FirstOrDefault( );
									nv3.Text = "30";

									NumericValue nv4 = nc.Elements<NumericPoint>( ).ElementAt( 3 ).Elements<NumericValue>( ).FirstOrDefault( );
									nv4.Text = "40";

									NumericValue nv5 = nc.Elements<NumericPoint>( ).ElementAt( 4 ).Elements<NumericValue>( ).FirstOrDefault( );
									nv5.Text = "50";

									NumericValue nv6 = nc.Elements<NumericPoint>( ).ElementAt( 5 ).Elements<NumericValue>( ).FirstOrDefault( );
									nv6.Text = "60";
								}
							}
						}
					}
				}
			}
		}
	}

The embedded chart is based off a 5 column (well actually 6 - the first column is row headers) x 6 row spreadsheet.

Any help would be much appreciated.

JP


JP





Write DataTable result to Excel using OpenXML

$
0
0

The following code converts a DataTable (the dt variable) into an array and then writes
the array into a Range on a worksheet (wsh var).

object[,] arr = new object[dt.Rows.Count, dt.Columns.Count];
for (int r = 0; r < dt.Rows.Count; r++)
{
  DataRow dr = dt.Rows[r];
  for (int c = 0; c < dt.Columns.Count; c++)
  {
    arr[r, c] = dr[c];
  }
}

Excel.Range c1 = (Excel.Range)wsh.Cells[topRow, 1];
Excel.Range c2 = (Excel.Range)wsh.Cells[topRow + dt.Rows.Count - 1, dt.Columns.Count];
Excel.Range range = wsh.get_Range(c1, c2);

range.Value = arr;

How do I perform this same thing using OpenXML instead of Interop? Given a two-dimensional array named arr, write values onto an Excel worksheet. I mean, I know you couldn't use an _Worksheet variable, you'd have to use the OpenXML equivalent.


Extract content from Word 2003 Document

$
0
0

Hi,

The client has Word 2003(.doc) documents in bulk  ,which are created based on a template (.dotm). The requirement is to extract the content (the actual data/paragraphs) from these documents. I know OpenXML is supported from 2007 onwards  ,so I have converted all .doc documents to .docx using OMPM (Office Migration Planning Manager). Now I've .docx docuemnts in a folder.

I've read many blogs on OpenXML on internet  ,but I'm not understanding.

Can anyone please help me to tell me the procedure to extract the content from these documents and store in a database ?? ORhow to convert these .docx to XML files using OpenXML ??? The requirement is to make this document data in SharePoint search..


Vipul Jain


AltChunks gives corrupted document.

$
0
0

Hi,

My Company generates a very large amount of Word documents that are assembled via OpenXML from data in a database. Some of the content is database fields which contains RTF text, which we add as AltChunks. This is very standard use of OpenXML, and it has been running along nicely for months. Recently, however, we discovered that some of the generated documents fail to open in Word.

When we try to open one of the bad documents, Word will complain and ask if we want to fix it, if we agree to that, Word fixes the document, but the content of the AltChunk is gone.

The issue is a bit of a headscratcher for us, because;

  • Some of the documents with RTF AltChunks open just fine,
  • All documents open fine with Word 2010 v.14.0.4760, but with Word 2010 v.14.0.6023, they won't.

So, it appears as if there's some RTF that Word doesn't like, not all, and that the dislike was introduced in a patch or update recently. Has anyone else experienced this issue?

Indentation problems in word 2007

$
0
0

Hi Everyone,

I am creating a word document using open xml sdk 2.5 using C#. I am generating the main content part, styles part, numbering part using XSLT. After finishing my work, when i opening the document in word 2010, all the indentations are coming properly. Have a look at the image below and see the indentation of 1.1.1. : 

Now when i am opening the same document in Word 2007, all the indentations are lost, they look like this:

When i did research for the root cause, then i came to know, that one of the indentation property (w:left) in the styles.xml is changed to (w:start) in word 2007. I have set this:

<w:pPr><w:adjustRightInd w:val="0"/><w:spacing w:before="120" w:after="120"/><w:jc w:val="both"/><w:ind w:left="360" /></w:pPr>

But it was changed to

<w:pPr><w:adjustRightInd w:val="0"/><w:spacing w:before="120" w:after="120"/><w:jc w:val="both"/><w:ind w:start="360" /></w:pPr>

My created word document should be compatible to word 2007 and word 2010. I need to preserve all the formatting in both the versions. So please let me know, how this problem can be handled?

Thanks,


Shahab Abbasi


OpenXML and powershell Copy of Worksheet to Workbook

$
0
0

Hello Everyone,

I looked at a few threads and quite didn't find a simple answer.

I have a powershell script that pulls SSRS reports in EXCELOPENXML format. These reports are pulled in a loop with different paramters and then subsequently consolidated as mutiple worksheets in to a single spreadsheet. I always take the first sheet of the SSRS report excel.

I am able to do this using excel interop and now want to scale this and schedule it as task. Excel doesn't usually liek that nor does MS support it.

I do want the sheet to be copied as-is including values, formatting, charts (future). Is this something easy to do in openXML and if someone has already created functions for it, please share

Here is the code snippet in powershell , this is in a for-each loop

SSRSexcelExport$tempfileName$_.Report_server.trimend()$_.Report_location.trimend()$_.No_of_parm$parm1$parmvalue1$parm2$parmvalue2$parm3$parmvalue3

$wb2=$xl.workbooks.open($tempfileName,$null,$true

$sheetfromCopy     =$wb2.sheets.item(1) # source worksheet

$sheetfromCopy.Name=$_.tab_name.trimend() #this the name I want in the destination worksheet

$sheettoCopy       =$wb1.sheets.item(1) # Insert as the first sheet in the destination

$sheetfromCopy.copy($sheettocopy)

$wb2.close($false

Problem with inserting html to tablecell

$
0
0

Hi everybody

I had a Problem with inserting Html string into table cell in a table. I used altchunk, and append it as a new child to one table cell. Afterwards I use MS word 2013 to open the generated document, everything is fine. But I open it with MS Word 2010 in my Office, the document always crashed. I used validator to validate the generated document, and it did NOT complain anything.

Has anybody  met the same Situation before? according to Openxml SDK 2.0(I copied the sample code, and it did NOT work), I should be able to insert html into table cell, and table cell is valid parent for altchunk. Is this a bug or I made any mistake? I have been fighting for days....no luck, Could anybody help?  

Cheers

Christy

Insert formatted text into bullet strings

$
0
0

Hi all,

I am new to Openxml, and currently got a problem with my project. I
am implementing a document genenrator, and in the template I have some list
strings. The text I want to use for updating the template list string are
formatted text. I tried to use altchunk, but the format is not correct. Could
anybody enlighted me the right/best way to do this? is altchunk one option? if
so, what might be the correct way to do it? Thank you very much in advance

Cheers

Christy

Why do I get errors with OpenxmlValidator but not with Productivity Tool?

$
0
0

I have a simple (mostly blank) World Document saved in .docx format from Word 2013.

OpenXmlValidator throws the following errors, yet the Productivity Tool says there are no errors.  Also some of the errors look suspiciously not like errors.  The document appears fine in Word.

Why the discrepancy?

I'm using OpenXML SDK 2.0, version 1.0.

ERRORS:

Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:p'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Body
Path: /w:document[1]/w:body[1]
Part: /word/document.xml
-------------------------------------------
Description: The attribute 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:name' has invalid value 'differentiateMultirowTableHeaders'. The Enumeration constraint failed.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.CompatibilitySetting
Path: /w:settings[1]/w:compat[1]/w:compatSetting[5]
Part: /word/settings.xml
-------------------------------------------
Description: Attribute 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:val' should have value(s) '11', '12' or '14' when attribute 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:name' has value(s) 'compatibilityMode'. Current value of attribute 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:val' is '15'.
ErrorType: Semantic
Node: DocumentFormat.OpenXml.Wordprocessing.CompatibilitySetting
Path: /w:settings[1]/w:compat[1]/w:compatSetting[1]
Part: /word/settings.xml
-------------------------------------------

Creating Powerpoint with charts using open xml

$
0
0

I wish to create a powerpoint file and then add charts to that file dymanically (chart on each page) through providing the chart title and the chart data and selecting one of the predefined charts titles.

I thought the easiest way to start was to create a presentation with 1 chart (1 slide) and generate code for that using the Open XML SDK tools.

But the code generated is too complicated to be easily read.

 

Please let me know what is the best way to do this?

Thanks in advance 

OpenXml - Insert Watermark in Word with VB.NET

$
0
0

I have a web applications (asp.net) and I need to insert text diagonal Watermark, in a word file (word 2010) with OpenXML, I use the following steps to open the file:

Dim wordmlNamespace As String = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"

Using wdDoc As WordprocessingDocument = WordprocessingDocument.Open(newPath, True) 
    
If wdDoc.MainDocumentPart.HeaderParts IsNot Nothing Then
	If wdDoc.MainDocumentPart.HeaderParts IsNot Nothing Then
		For Each Headerpart In wdDoc.MainDocumentPart.HeaderParts
			Dim r As DocumentFormat.OpenXml.Wordprocessing.Run = CreateWatermarkRun("watermarkText")
			Dim para As New DocumentFormat.OpenXml.Wordprocessing.Paragraph
			para.Append(r)
			Headerpart.Header.Save(Headerpart)
		Next
    End If
End If

wdDoc.MainDocumentPart.Document.Save()
wdDoc.Close()

End Using

The function CreateWatermarkRun is this

Private Function CreateWatermarkRun(ByVal name As String) As DocumentFormat.OpenXml.Wordprocessing.Run

    Dim runWatermark As New DocumentFormat.OpenXml.Wordprocessing.Run()

    Dim runWMProperties As New DocumentFormat.OpenXml.Wordprocessing.RunProperties()
    Dim noProofWM As New DocumentFormat.OpenXml.Wordprocessing.NoProof()

    runWMProperties.Append(noProofWM)

    Dim pictureWM As New DocumentFormat.OpenXml.Wordprocessing.Picture()

    Dim shapetypeWM As New DocumentFormat.OpenXml.Vml.Shapetype() With
    { _
        .Id = "_x0000_t136", _
        .CoordinateSize = "21600,21600", _
        .OptionalNumber = 136, _
        .Adjustment = "10800", _
        .EdgePath = "m@7,l@8,m@5,21600l@6,21600e" _
    }

    Dim formulasWM As New DocumentFormat.OpenXml.Vml.Formulas()
    Dim formula1 As New DocumentFormat.OpenXml.Vml.Formula() With { _
     .Equation = "sum #0 0 10800" _
    }

    Dim formula2 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "prod #0 2 1" _
    }

    Dim formula3 As New DocumentFormat.OpenXml.Vml.Formula() With { _
     .Equation = "sum 21600 0 @1" _
    }

    Dim formula4 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "sum 0 0 @2" _
    }

    Dim formula5 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "sum 21600 0 @3" _
    }

    Dim formula6 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "if @0 @3 0" _
    }

    Dim formula7 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "if @0 21600 @1" _
    }

    Dim formula8 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "if @0 0 @2" _
    }

    Dim formula9 As New DocumentFormat.OpenXml.Vml.Formula() With { _
     .Equation = "if @0 @4 21600" _
    }

    Dim formula10 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "mid @5 @6" _
    }

    Dim formula11 As New DocumentFormat.OpenXml.Vml.Formula() With { _
     .Equation = "mid @8 @5" _
    }
    Dim formula12 As New DocumentFormat.OpenXml.Vml.Formula() With { _
     .Equation = "mid @7 @8" _
    }

    Dim formula13 As New DocumentFormat.OpenXml.Vml.Formula() With { _
      .Equation = "mid @6 @7" _
    }

    Dim formula14 As New DocumentFormat.OpenXml.Vml.Formula() With { _
     .Equation = "sum @6 0 @5" _
    }

    formulasWM.Append(formula1)
    formulasWM.Append(formula2)
    formulasWM.Append(formula3)
    formulasWM.Append(formula4)
    formulasWM.Append(formula5)
    formulasWM.Append(formula6)
    formulasWM.Append(formula7)
    formulasWM.Append(formula8)
    formulasWM.Append(formula9)
    formulasWM.Append(formula10)
    formulasWM.Append(formula11)
    formulasWM.Append(formula12)
    formulasWM.Append(formula13)
    formulasWM.Append(formula14)
    Dim pathWM As New DocumentFormat.OpenXml.Vml.Path() With { _
      .AllowTextPath = True, _
      .ConnectionPointType = DocumentFormat.OpenXml.Vml.Office.ConnectValues.[Custom], _
      .ConnectionPoints = "@9,0;@10,10800;@11,21600;@12,10800", _
      .ConnectAngles = "270,180,90,0" _
    }
    Dim textPathWM As New DocumentFormat.OpenXml.Vml.TextPath() With { _
      .[On] = True, _
      .FitShape = True _
    }

    Dim shapeHandlesWM As New DocumentFormat.OpenXml.Vml.ShapeHandles()
    Dim shapeHandleWM As New DocumentFormat.OpenXml.Vml.ShapeHandle() With { _
     .Position = "#0,bottomRight", _
     .XRange = "6629,14971" _
    }

    shapeHandlesWM.Append(shapeHandleWM)
    Dim lockWM As New DocumentFormat.OpenXml.Vml.Office.Lock() With { _
     .Extension = DocumentFormat.OpenXml.Vml.ExtensionHandlingBehaviorValues.Edit, _
     .TextLock = True, _
     .ShapeType = True _
    }

    shapetypeWM.Append(formulasWM)
    shapetypeWM.Append(pathWM)
    shapetypeWM.Append(textPathWM)
    shapetypeWM.Append(shapeHandlesWM)
    shapetypeWM.Append(lockWM)

    Dim shapeWM As New DocumentFormat.OpenXml.Vml.Shape() With { _
     .Id = "PowerPlusWaterMarkObject346762751", _
     .Style = ";margin-left:0;margin-top:0;width:527.85pt;height:131.95pt;rotation:315;z-index:-251655168;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin", _
     .OptionalString = "_x0000_s2050", _
      .AllowInCell = False, _
      .FillColor = "silver", _
      .Stroked = False, _
      .Type = "#_x0000_t136" _
    }

    Dim fillWM As New DocumentFormat.OpenXml.Vml.Fill() With { _
      .Opacity = ".5" _
    }

    Dim textPath2WM As New DocumentFormat.OpenXml.Vml.TextPath() With { _
     .Style = "font-family:""Arial"";font-size:1pt", _
     .[String] = name _
    }

    shapeWM.Append(fillWM)
    shapeWM.Append(textPath2WM)

    pictureWM.Append(shapetypeWM)
    pictureWM.Append(shapeWM)

    runWatermark.Append(runWMProperties)
    runWatermark.Append(pictureWM)

    Return runWatermark

End Function

When I run my web application, not return errors, but not print nothing.

Thanks!

Power Point pptx auto fit text

$
0
0

Hello!

I am writing a pptx generator. I am putting text into slides. I want that it take determine width. For excample, text "param pam pam" should take 1.5 inch. For it purpose I put <a:normAutofit /> in <a:bodyPr ..> in <p:txBody> in... slideN.xml

If generated xml text block has not enough width to contain some text, than some part of this text will be translate to next line in text block. I use <a:normAutofit /> http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.normalautofit(v=office.14).aspx without attributes (fontScale, lnSpcReduction) because I don’t know what ratio I need in each textblock. But if I use PowerPoint application to open my generated file and after it I change some shape position, than PowerPoint automatically rebuild all text blocks on slide in a right way. As result my text "param pam pam" takes 1.5 inch.

Question is: how rebuild all text in my presentation automatically? Can I do it in XML or I need use PowerPoint COM model?

I tried to open my generated pptx throw PowerPoint COM model. Then I made some modification (text was rebuild), then I saved presentation and it looked like ok. But when I used presentation with many slides (1300 for example ), I got rebuild text only on first several slides, all other slides had “bad” text.

My next try was:  I tried to make modification throw COM model to each slide in cycle and I resaved presentation. I got document with some bad text and some good text…

Next test: I tried to do it  throw PowerPoint by hands. I opened presentation and began make changes in each few slides, the result was ok – text on all processed slides has been rebuild. After it I renamed pptx file to the zip, uncompressed it and looked on slideN.xml. I had found than PowerPoint added fontScale and lnSpcReduction attributes with different values.

How to make autofit in whole document? I hope PowerPoint COM model has some “refresh/update” method which can guaranty rebuild all text in document. Or OpenXML has some flag which can help me.

Part of my bigtest pptx you can find here

https://onedrive.live.com/redir?resid=D3D1964EFDBEF026!291&authkey=!AB68jEPGOM94Yrw&ithint=file%2c.pptx




Add custom properties to ".xlsb" files using openxml sdk in VB.net/C#.net

$
0
0

Hi,

I am creating an asp.net application which adds custom properties in office documents.

I am using open xml sdk dll for adding custom properties for xlsm, xlsx files.

I am using SpreadSheetDocument.open (..)  for adding custom properties.

But i am not able to add custom properties in .XLSB files using SpreadSheetDocument.open (..)

Is there any other way of adding custom properties from .xlsb

XLSM and XLSX are working fine using SpreadSheetDocument.open (..)

Please help and suggest how can i add custom properties in .XLSB files using openxml sdk package dlls.

or any other class would be fine.

I also have tried using dsofile dll. But on servers it is giving issues with office 2007 and above formats.

Coloring cells in excel sheet using openXML in C#

$
0
0

Hi,

Please explain, how to color the two different cells (C4,F6) with two different colors in the excel sheet using OpenXML in C#.

thanks,

Elangovan P

 

Can't install -- Open XML SDK 2.5 is not supported on .NET Framework Version 4.5 - is there a workaround?

$
0
0

My corporate client provided me a high powered laptop (with secure network access) for development purposes.   When I attempt to install the OpenXMLSDKV25.msi it reports "You should have .NET Framework 4.0 installed before you setup Open XML SDK 2.5..."

Visual Studio shows that my laptop has Microsoft .NET Framework Version 4.5.50709 installed

Is there a work-around so that I can get it installed? 


MCAD.NET C# - http://www.Global-webnet.com/Blog

.NET application - reopen word at particular bookmark

$
0
0

Hi

There is a requirement to open a word in browser (IE9) at the particular bookmark/page on link click of web application page.

Application Details: .Net 4.5/Asp.Net MVC application

I have the following queries to identify the valid approach that will help me to complete this functionality.

1. In first level, Is it technically fessiable with ASP.NET MVC application?

2. If possible, Can we achive through Interop.Word (sdk) or should be used Open XML?

3. If possible, would throw any threading issues when multiple user access same document (at client-side) since it is server (IIS) based application?

Note: installing word in Server is not possible but every user node will have word software.

It should be veryful if somebode throw some light to procced further.

Thanks in advance.


VMLDrawing part

$
0
0

Hi,

The code part  VmlDrawingPart vmlDrawingPart = worksheetPart.AddNewPart<VmlDrawingPart>(); from the below given link is not working for me.I'm getting an exception saying that "only one instance of the type is allowed for this parent". Can anyone help??

 

http://social.msdn.microsoft.com/forums/office/en-US/40a95862-9adc-492d-a046-97a5e6e20260/how-to-insert-comments-in-excel-using-openxml

Thanks

Viewing all 1288 articles
Browse latest View live


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