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

Using OpenXML to replace formatted text in Word document

$
0
0

Hi

In one of my projects I must replace Word automation functionality with Open XML.

The project takes a formated Word template(.dotx) and replace predefined images, textboxes and bookmarks with images, plain text and html-formatted text, and then returns it.

Now, what would be the best solution here?

I guess the image replacement is pretty straightforward, and so is the plain text parts.
But what about the bookmarks where I today uses Document.ActiveWindow.Selection.InsertFile(htmlFormattedText).

Should I switch to Content Controls instead of bookmarks?
If so, how do I insert html formatted text into a content control and also, how do I identify it?

Thanks in advance


Best Regards Peter Karlström Midrange AB, Sweden



Help with "The process cannot access the file..." error. Bulk number insert.

$
0
0

Hi All,

I am using a number insert function I found here (http://msdn.microsoft.com/en-us/library/bb508943(v=office.12).aspx) to insert number values into cells in a new spreadsheet document.

Works great with one exception.  I have hundreds of numbers to insert into hundreds of cells.  The code works well on a few inserts, but after it gets to around 200 or so inserts, I continually get the error:"The process cannot access the file 'blah\blah\blah.xlsx' because it is being used by another process."

Can someone give me some pointers on how to avoid this?  Is there a bulk number insert function I should be using instead?  As it is now, I am simply using a for each loop around code similar to this:

OpenXMLFunctions.XLInsertNumberIntoCell(xlsxFilename, "Sheet1", "C" & i + 1, myDouble)

Like I said... works well until it approaches 200 or so inserts then I get the error. Almost as if the system can't keep up with all of the open and closes.  To test this theory I added the following after each XLInsertNumberIntoCell call:

System.Threading.Thread.Sleep(100)

Sure enough, the code completes successfully.  The downside is this really slows down the code. 100 is the shortest timeout value I can use that still allows the code to complete. Anything slower and it errors out.

Thanks in advance!

Setting chart line color

$
0
0

How could I set the color of the line in line chart (presentation)? I take the template and change data for the chart, I found a "Marker" property in LineChartSeries so I can change a marker of the line, but how can I change the color (it would be provided to the generating function)?


UPD

Analyzing PowerPoint-generated XML after changing line color and my presentation XML I managed it. Solution looks like this:

lineChartSeries.ChartShapeProperties = new ChartShapeProperties();
var outline = lineChartSeries.ChartShapeProperties.AppendChild<DocumentFormat.OpenXml.Drawing.Outline>(new DocumentFormat.OpenXml.Drawing.Outline());
var solid = outline.AppendChild<DocumentFormat.OpenXml.Drawing.SolidFill>(new DocumentFormat.OpenXml.Drawing.SolidFill());              
solid.AppendChild<Drawing.RgbColorModelHex>(new Drawing.RgbColorModelHex() { Val = new HexBinaryValue() { Value = "ff0000" } });

I wonder if they could make changing the color as easy as changing line marker. Just for information it can be done like this:

lineChartSeries.Marker = new Marker() { Symbol = new Drawing.Charts.Symbol() { Val = MarkerStyleValues.Diamond } };




Powerpoint SlideXML not stable

$
0
0

Hello,

We are trying to use the content of each Slide.xml to identify the given slide is modified or not.

But in our C# automation for reading the Slide.XML we found. Powerpoint itself automatically modified internally other non modified slide and rearrange the open XML structure or put tags like below

<a:r>
<a:rPr lang="en-US" dirty="0" smtClean="0" />
<a:t> 
.
</a:t>
</a:r>

Any other better mechanism to how to avoid this? or find a modified slide?

Error while open the excel sheet

$
0
0

Hi,

   I loaded the values in excel sheet by using open xml, but while open the excel sheet it show the error message like below, can you tell me how to address this errors? is any specific tool available to address this errors?

Error during open the excel sheet

$
0
0

When i open the excel sheet, i am getting following popup, so i compare two excel file(with errro popup, without error popup), so i got below(screen short2), but i could not able to find exact error and which field causing error, so can any one help me to solve this issue.

Screen Short1:

Screen Short2:

How to execute/call macro in .xlsm file using Office Open XML SDK 2.0

$
0
0

I would like to know how OpenXML API can be used to run macros with .xlsm files? I'm using Open XML API in my project and using "using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(excelPath, true))" to open the excel file and then inserting the values in excel file using Open XML API's, through a windows service.

ISSUE -  After inserting the values, we are uploading the .xlsm file to a SharePoint library. When user/client opens the file, .xlsm file opens and We are running a macro (implementing formulas) on open event of the excel. However, when user open in Office 2010, they don't see their data populated through macro but when they open in Office Excel 2013, the macro runs properly, and data is also populated.

Question - I think this is the issue related to "How we are calling MACRO". Can we call our macro through .NET C# Code in OPEN XML API instead of calling on open event of excel file itself..? Through this way, I think, we will also be able to present .xlsx file to our client (as client needs .xlsx file and not .xlsm).

Please suggest !!!


Vipul Jain

Protecting Excel file created through OpenXML

$
0
0

Hello,

I want to protect Excel file 2007+ version (xlsx), which is created through OpenXML 2.0. I am able to protect the file through zipped format. I am not able to find the help to protect the Excel file i.e., assigning password to open for Excel file. This is not the help for protecting the worksheet.

Can anybody help me out?


The hostname could not be parsed excetion at SpreadsheetDocument.Open(fileName, editable) in VS2013

$
0
0

Hi,

I have opened a VS2010 Console application in VS2013.(Migration happened automatically)

Now, I am trying to open an document using

SpreadsheetDocument.Open(fileName, editable)

and fileName is "C:\\TestAutomationEnvironment\\UIControlsDescription\\UIControlsDescription.xlsx"

and at this open we are getting

The hostname could not be parsed excetion.

and it was working fine with VS2010.

Whether it is producing the exception because of VS2013?

SmartArt Algorithm

$
0
0

Is there someone could help me ,some problem with SmartArt in office 2007. i konw SmartArt have  snake Algorithm,linear Algorithm and so on,but i can't get the right position of shape's and the right width of shape's,is there some information forget,or some information in Algorithm i can't get?

i would be happy to any answer.Thanks!

Excel Pagination Issue

$
0
0

Hi,

I am using office open sdk to create Excel files. But when we are opening the same excel in Windows and Mac operating systems, its showing different number of columns on each page while we set layout as page layout. All page setup settings are same.

For reference, I am attaching screen shot of generated excel sheet. In first Screen Shot, which refers to windows is showing 10 columns. In second screen shot, which refers to Mac is showing 9 columns.

Please help me out.

Thanks,

Naveen Khanna

Exporting data and chart to excel using openxml asp.net mvc

$
0
0

Hi,

I am new to OpenXML,

I have two requirement that has to completed using ASP.NET MVC and OpenXML(or any option).

Requirement 1. Data and chart has to be exported to MS excel (on click of button user should be given option to save or open directly - just like downloding document from internet)

Requirement 2. In the exported excel, when the user changes the data, the chart also need to change based on value(just like creating chart in MS excel and changing its data)

Is this possible in OpenXML, If possible is there any refernce document. If not possible is there any other way to achive this. Interop excel libarary is ruled out since we cannot install excel in production server.

Please help me!

Thanks

soniya

Open XML SDK v2 Handling Multiple Threads

$
0
0

Hi

I have read a post or two that suggests the open XML sdk is not thread safe but I haven't found any official MS document that states this in fact to the contrary most online docs demonstrate how to use the SDK for serverside creation of office documents. I'm prototyping a windows service that reads MSMQ and dispatches a thread to export some data to excel using open xml sdk v2.  The thread is created by calling BeginInvoke on a delegate and ultimately calls this code:

using

(SpreadsheetDocument workBook =SpreadsheetDocument.Open(exportFileInfo.FullName,true))

{

 

WorkbookHelper workBookHelper =newWorkbookHelper(workBook.WorkbookPart, tableName);

exportRowCount =

this.DataBind(workBookHelper, datasource);

workBook.WorkbookPart.Workbook.Save();

workBook.Close();

 

 

return exportRowCount;

}

If I allow 2 or more threads to run concurrently:

  • The code never finishes when I try to export 10000 rows. (I suspect I'm getting deadlock but not sure how to verify this). 
  • It does work if I try to export 5000 rows or less.

If I comment out the calls to save() and close() the code always finishes no matter how many threads I allow to run.  If I allow just one thread to run the exports always works.

Is there a threading problem in the SDK related to saving and closing workbooks and if so is there a plan to fix it soon?

Other than synchronising the entire block of code above is there a way I can I fix the problem myself?

Regards







 

how to write RTF to docx file

$
0
0

i have RTF store in string, how is the best way to insert it to docx via open xml.

the follwing go do the job but the document open with error.

 

using (WordprocessingDocument myDoc =
		  WordprocessingDocument.Open("RtfTest2.docx", true))
		{string val = @"{\rtf1 \b Hello world! \b0 }";


			MainDocumentPart mainPart = myDoc.MainDocumentPart;
			//Find content controls that have the name of the source file as // an alias value. 
			List<SdtBlock> sdtList = mainPart.Document.Descendants<SdtBlock>().Where(s =>"RichText".Contains(s.SdtProperties.GetFirstChild<Tag>().Val.Value)).ToList();if (sdtList.Count != 0)
			{string altChunkId = "AltChunkId" + Guid.NewGuid();
				AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);// convert string to stream  byte[] byteArray = Encoding.ASCII.GetBytes(val);using (var stream = new MemoryStream(byteArray))
				{
					chunk.FeedData(stream);
				}var altChunk = new AltChunk();
				altChunk.Id = altChunkId;//Replace the content control with altChunk information. foreach (SdtBlock sdt in sdtList)
				{
					OpenXmlElement parent = sdt.Parent;
					parent.InsertAfter(altChunk, sdt);
					sdt.Remove();
				}
				mainPart.Document.Save();
			}
		}


please help..


tt

Looking for examples using OpenXML SDK

$
0
0

I am looking for examples of using the OpenXML SDK such as

  • Opening a DOCX or xlsx or xlsm
  • Select specific sub xml files in a docx, xlsx, or xlsm
  • Search for and parse specific node  in the sub xml file
  • What is best tool for this? Something like xPath or other

Thank you,

Jim


Jim


Reading heavy excel files page wise using OpenXML

$
0
0

Hi, 

I am using OpenXML to read heavy excel files, but I am using paging to read files because I have to process data and show in Grid on frontend. 

Problem here is for reading every page of 10000 records its time is increasing. 

First Page = 38397 Milliseconds

Second Page = 81910 MS

Third page =117923 MS

Fourth page =150142 MS

Any body has any clue...

Help with "The process cannot access the file..." error. Bulk number insert.

$
0
0

Hi All,

I am using a number insert function I found here (http://msdn.microsoft.com/en-us/library/bb508943(v=office.12).aspx) to insert number values into cells in a new spreadsheet document.

Works great with one exception.  I have hundreds of numbers to insert into hundreds of cells.  The code works well on a few inserts, but after it gets to around 200 or so inserts, I continually get the error:"The process cannot access the file 'blah\blah\blah.xlsx' because it is being used by another process."

Can someone give me some pointers on how to avoid this?  Is there a bulk number insert function I should be using instead?  As it is now, I am simply using a for each loop around code similar to this:

OpenXMLFunctions.XLInsertNumberIntoCell(xlsxFilename, "Sheet1", "C" & i + 1, myDouble)

Like I said... works well until it approaches 200 or so inserts then I get the error. Almost as if the system can't keep up with all of the open and closes.  To test this theory I added the following after each XLInsertNumberIntoCell call:

System.Threading.Thread.Sleep(100)

Sure enough, the code completes successfully.  The downside is this really slows down the code. 100 is the shortest timeout value I can use that still allows the code to complete. Anything slower and it errors out.

Thanks in advance!

Setting chart line color

$
0
0

How could I set the color of the line in line chart (presentation)? I take the template and change data for the chart, I found a "Marker" property in LineChartSeries so I can change a marker of the line, but how can I change the color (it would be provided to the generating function)?


UPD

Analyzing PowerPoint-generated XML after changing line color and my presentation XML I managed it. Solution looks like this:

lineChartSeries.ChartShapeProperties = new ChartShapeProperties();
var outline = lineChartSeries.ChartShapeProperties.AppendChild<DocumentFormat.OpenXml.Drawing.Outline>(new DocumentFormat.OpenXml.Drawing.Outline());
var solid = outline.AppendChild<DocumentFormat.OpenXml.Drawing.SolidFill>(new DocumentFormat.OpenXml.Drawing.SolidFill());
solid.AppendChild<Drawing.RgbColorModelHex>(new Drawing.RgbColorModelHex() { Val = new HexBinaryValue() { Value = "ff0000" } });

I wonder if they could make changing the color as easy as changing line marker. Just for information it can be done like this:

lineChartSeries.Marker = new Marker() { Symbol = new Drawing.Charts.Symbol() { Val = MarkerStyleValues.Diamond } };




Using OpenXML to replace formatted text in Word document

$
0
0

Hi

In one of my projects I must replace Word automation functionality with Open XML.

The project takes a formated Word template(.dotx) and replace predefined images, textboxes and bookmarks with images, plain text and html-formatted text, and then returns it.

Now, what would be the best solution here?

I guess the image replacement is pretty straightforward, and so is the plain text parts.
But what about the bookmarks where I today uses Document.ActiveWindow.Selection.InsertFile(htmlFormattedText).

Should I switch to Content Controls instead of bookmarks?
If so, how do I insert html formatted text into a content control and also, how do I identify it?

Thanks in advance


Best Regards Peter Karlström Midrange AB, Sweden


Powerpoint SlideXML not stable

$
0
0

Hello,

We are trying to use the content of each Slide.xml to identify the given slide is modified or not.

But in our C# automation for reading the Slide.XML we found. Powerpoint itself automatically modified internally other non modified slide and rearrange the open XML structure or put tags like below

<a:r>
<a:rPr lang="en-US" dirty="0" smtClean="0" />
<a:t> 
.
</a:t>
</a:r>

Any other better mechanism to how to avoid this? or find a modified slide?

Viewing all 1288 articles
Browse latest View live


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