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

OpenXML Presentation - Identifying paragraphs...

$
0
0

I have an interesting problem that I would like to throw out to you all - see if anyone can think of anything I haven't.

What I need to be able to do here is to somehow assign / determine identifers for all the paragraphs in a Presentation. I then need to be able, at some point in the future, to open / manipulate that presentation using OpenXML, and the identifiers have to be available for use at this point.

In short then, I need some form of persistent identifier.

I've tried looking at the OpenXMLFormat itself, and cannot see anything there that I can use that's already built in. If anyone knows of anything, any element that's already in the schema I might use, any attribute etc, then please shout up...

Trying to solve this problem myself, I have written code using XLinq and SharpZipLib to open up the various xml files and add a custom attribute to every element - the attribute basically containing a Guid. The code does what it is supposed to - but both Powerpoint and OpenXML 2.5 will then no longer talk to the file - presumably because I have introduced attributes that are not in the schema... I could live without Powerpoint being able to access the file at this point, but OpenXML is a bit of a blocker because the file will be undergoing some processing later on that has a definite dependency on the OpenXml library.

Anyone got any ideas?


Dealing with w:object(EmbeddedObject) using Open XML Format

$
0
0

First of all, I want to thank OOXML team for building a wonderful SDK like Open XML. It reads document like a charm and its so native feels like I am inside a word document with all its contents. Hats off to the developers.

I am a newbie to OOXML and its formats, therefore I need your help to understand it to develop an application which reads document using the SDK (v2.5).

I am using Visual Studio 2013 Express Edition to start with and installed OOXML Libraries along with Power Tools, Simple OOXML. I am able to read the documents using the following code (Contains questions with-in)

/// <summary>
/// Open the word document to process package readonly.
/// </summary>
/// <param name="filePath">Path to the word document</param>
/// <returns>success/failure message</returns>
public static string OpenWordprocessingPackageReadonly(string filePath)
{
	if (filePath == null)
	{
		return string.Format("Invalid FilePath.. Check your entries... FilePath: {0}", filePath);
	}

	// Open System.IO.Packaging.Package.
	Package wordPackage = Package.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);

	// Open a WordprocessingDocument based on a package
	using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(wordPackage))
	{
		MainDocumentPart mainDocumentPart = wordDocument.MainDocumentPart;

		// Assign a reference to the existing document body.
		Body body = mainDocumentPart.Document.Body;

		foreach (Table table in body.Descendants<Table>())
		{
			int tableRowIndex = 0;
			foreach (TableRow tableRow in table.Descendants<TableRow>())
			{
				int tableCellIndex = 0;

				// Loop through each cell to get the content of the cell.
				foreach (TableCell tableCell in tableRow.Descendants<TableCell>())
				{// TODO Can we convert these tables into images?
					foreach (Table tableInstace in tableCell.Descendants<Table>())
					{
						// Table should be converted to image.
						System.Diagnostics.Trace.WriteLine(
							string.Format("Found Table Object in row: {0}, cell: {1}", tableRowIndex, tableCellIndex));
						// Run a macro to convert this.
					}// TODO Can we convert these paragraphs to HTML or XHTML?
					foreach (Paragraph paragraph in tableCell.Descendants<Paragraph>())
					{
						StringBuilder buildText = new StringBuilder();

						foreach (Run run in paragraph.Descendants<Run>())
						{// TODO Can we convert these embedded objects into png images?
							foreach (EmbeddedObject embObject in run.Descendants<EmbeddedObject>())
							{
								// Convert this to png images.
							}// TODO Can we convert these pictures (assuming these are not already png) into png images?
							foreach (Picture picture in run.Descendants<Picture>())
							{
								// Process the picture object.
								// Process round rectangle as well.
								// Process drawingml for Normal Pictures, Auto-Shapes, Charts
								System.Diagnostics.Trace.WriteLine(
									string.Format("Found Picture Object in row: {0}, cell: {1}", tableRowIndex, tableCellIndex));
								//picture.Descendants<>
							}
							foreach (Text text in run.Descendants<Text>().Where<Text>(textPredicate => (textPredicate.Parent.GetType().IsAssignableFrom(typeof(Run)))))
							{
								buildText.Append(text.Text);
							}
						}
					}
					tableCellIndex += 1;
				}
				// Goto the next row
				tableRowIndex += 1;
			}
		}

		TableIndex += 1;
	}

	// Close the package
	wordPackage.Close();
}

I have the following questions:

1. Is there a way where I can read the document in a better way than the above? - The document contains 2 or more tables and each table contains 15-20 columns in it. Each cell can contain any type including tables, shapes, auto-shapes, images, bullets and numbering etc., also symbols.

2. Is it possible to convert WMF, EMF, EMF+, EmbeddedOLEObjects to PNG or Bitmap images?

3. Is it possible to convert tables into Images? - The reason I want to do this is, these tables contains a lot of formatted data which if I read it as html or xml, will miss them. Thats why want to directly convert to images.

4. Is it possible to convert a paragraph to XHTML or HTML so that I can render the same in the UserInterface?

All these questions bothering me from past 3 days and I am struggling to get an answer. Any help in this forum is well appreciated.

Please guide me either a direct help in code or links to the code which help me learn to code.

Let me know,

Thanks,

Triguna



How can color plus white?

$
0
0

In the ECMA Office Open XML document <Fundamentals and And Markup Language Reference> page 2966, it's said that the specular color of "Metal" is shape fill color plus white. how can a kind of color plus white? what is the resulted rgb?

in addition:

1) what is 'shape color darken by add black' and 'shape fill color lightened with white by 50%'?

2)what is rgb of 'very light grey'?

thanks

Chunk misunderstand accents

$
0
0

hello,

I created a docx with openxml APIs. This includes chunks containing hmtl code (simple code with accents like "<html><head></head><boy><div>je vis à Yverdon</div></body>").

When I edit this docx in word, first chunk is fine, second chunk scrambles the à to another strange special character.

I rename the docx to zip, dirll down, copy afchunk2.xhtml to another directoy, copy back to zip, rename to docx, edit. Still wrong

I rename the docx to zip, dirll down, copy afchunk2.xhtml to another directoy, edit it with note pad, DNO NOT change anything but save it (so, change timetstamp), copy back to zip, rename to docx, edit. It is now correct !

What the hell in all that ?

Thanks

Comment Formatting in ExcelXML

$
0
0

This is specific to creating .xml files that open in MSExcel as spreadsheets, that contain cell comments:

Is there any way to specify the comment window size or position? 

Is there any way to set the default comment window size?

I can manually modify the size and position and save it to XML, but when I re-open it's back to the default.

Most important would be setting the width, secondly the height.

Or, any way to have it auto-size?

P.S.  I've found that I can insert &#13;&#10; to force new lines, but the default comment window is always too narrow.

Create hyperlink and populating it in excel sheet using Open XML sdk

$
0
0

I am trying to populate hyperlink in excel sheet using Open Office xml sdk.

Description of Excel sheet:

The excel sheet contains 3 tables –

  • Table 1
  • Table 2
  • Table 3

Table 1 and Table 3 already contains some data along with hyperlinks. Now I want to populate hyperlink and other data in table 2 of excel sheet.

I am using following code, but getting following error while opening the excel sheet:

We found a problem with some content in 'Sheet.xlsx'. Do you want us to try to recover as much as we can?If you trust the source of this workbook, click Yes.

After click on Yes, getting another error:

Excel was able to open the file by repairing or removing the unreadable content.

And after closing this error message, sheet data gets empty

I am using following code:

//Method to sheet data and hyperlink        
private bool PopulateHyperlink(SpreadsheetDocument myWorkbook)
        {
            #region Variables
            bool success = false;            
            Cell toolcelloffering = null;
            Cell toolcellvendor = null;
            Cell toolcellname = null;
            Cell toolcellfunction = null;
            Sheet sheet = null;
            WorksheetPart worksheetPart = null;
            string columnname = string.Empty;
            string toolUrl = string.Empty;
            int i = 1;
            Row row;
            DocumentFormat.OpenXml.UInt32Value sheetId;
            SheetData sheetData;
            var toolOffering = string.Empty;
            List<Tool> toolList = null;
            Hyperlinks hyperlinks1 = new Hyperlinks();
            //Get these values from web.config
            int ToolsColumn=2;
            int ToolsRow=17;
            int ToolsColumnValue=2;
            #endregion
            try
            {
                sheet = myWorkbook.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>().First(s => s.Name.Value.Equals("SheetName", StringComparison.OrdinalIgnoreCase));
                worksheetPart = (WorksheetPart)myWorkbook.WorkbookPart.GetPartById(sheet.Id.Value);
                sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();                
                if (Project.Tools != null)
                {
                    //removing duplicate records from Tools list
                    toolList = Project.Tools.GroupBy(p => p.Name).Select(g => g.First()).ToList();
                    //Loop through the Tools of the project
                    foreach (Tool tool in toolList)
                    {                           
                        toolUrl = tool.URL;                           
                        columnname = GetColumnName(ToolsColumn);
                        toolcellname = GetCellInWorksheet(columnname, Convert.ToUInt32(17), worksheetPart);
                        toolcellname.CellValue = new CellValue(tool.Name.Replace("amp;", string.Empty));
                        toolcellname.DataType = new EnumValue<CellValues>(CellValues.String);
                        toolcellname.StyleIndex = 130;
                        if (!string.IsNullOrEmpty(toolUrl))
                        {
                            toolcellname = CreateHyperLink(myWorkbook, worksheetPart, toolUrl, columnname, toolcellname, i, hyperlinks1, ToolsRow, tool.Name);
                            columnname = string.Empty;
                        }
                        ToolsColumn++;
                        ToolsColumn = ToolsColumnValue;
                        //Increment the row to add the next tool information.
                        ToolsRow++;
                        i++;
                    }
                    PageMargins pageMargins = worksheetPart.Worksheet.Descendants<PageMargins>().First();
                    worksheetPart.Worksheet.InsertBefore<Hyperlinks>(hyperlinks1, pageMargins);
                    worksheetPart.Worksheet.Save();
                }
                success = true;
            }
            catch (Exception ex)
            {
                throw new Exception("Exception while populating the information. " + ex.Message);
            }
            return success;
        }
        //Method to create hyperlink
        private Cell CreateHyperLink(SpreadsheetDocument myWorkbook, WorksheetPart worksheetPart, string url, string columnname, Cell cellName, int i, Hyperlinks hyperlinks, int row, string name)
        {
            Hyperlink hyperlink = new Hyperlink();
            hyperlink.Reference = columnname + row;
            hyperlink.Id = "UNIQUE" + i;
            hyperlinks.Append(hyperlink);
            worksheetPart.AddHyperlinkRelationship(new System.Uri(url, System.UriKind.Absolute), true, hyperlink.Id);
            // Create an element in SheetData
            // Get the SharedStringTablePart. If it does not exist, create a new one.
            SharedStringTablePart shareStringPart;
            if (myWorkbook.WorkbookPart.GetPartsOfType<SharedStringTablePart>().Count() > 0)
            {
                shareStringPart = myWorkbook.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First();
            }
            else
            {
                shareStringPart = myWorkbook.WorkbookPart.AddNewPart<SharedStringTablePart>();
            }
            // Insert the text into the SharedStringTablePart.
            int index = InsertSharedStringItem(name.Replace("amp;", string.Empty), shareStringPart);            
            cellName = GetCellInWorksheet(columnname, Convert.ToUInt32(row), worksheetPart);
            cellName.CellValue = new CellValue(index.ToString());
            cellName.DataType = new EnumValue<CellValues>(CellValues.SharedString);
            cellName.StyleIndex = 134;
            return cellName;
        }
        private Cell GetCellInWorksheet(string columnName, uint rowIndex, WorksheetPart worksheetPart)
        {
            Worksheet worksheet = worksheetPart.Worksheet;
            SheetData sheetData = worksheet.GetFirstChild<SheetData>();
            string cellReference = columnName + rowIndex;
            // If the worksheet does not contain a row with the specified row index, insert one.
            Row row;
            if (sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).Count() != 0)
            {
                row = sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).First();
            }
            else
            {
                row = new Row() { RowIndex = rowIndex };
                sheetData.Append(row);
            }
            // If there is not a cell with the specified column name, insert one.  
            if (row.Elements<Cell>().Where(c => c.CellReference.Value == columnName + rowIndex).Count() > 0)
            {
                return row.Elements<Cell>().Where(c => c.CellReference.Value == cellReference).First();
            }
            else
            {
                // Cells must be in sequential order according to CellReference. Determine where to insert the new cell.
                Cell refCell = null;
                foreach (Cell cell in row.Elements<Cell>())
                {
                    if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)
                    {
                        refCell = cell;
                        break;
                    }
                }
                Cell newCell = new Cell() { CellReference = cellReference };
                row.InsertBefore(newCell, refCell);
                worksheet.Save();
                return newCell;
            }
        }
        private string GetColumnName(int columnNumber)
        {
            StringBuilder retVal = new StringBuilder();
            int x = 0;
            for (int n = (int)(Math.Log(25 * (columnNumber + 1)) / Math.Log(26)) - 1; n >= 0; n--)
            {
                x = (int)((Math.Pow(26, (n + 1)) - 1) / 25 - 1);
                if (columnNumber > x)
                    retVal.Append(System.Convert.ToChar((int)(((columnNumber - x - 1) / Math.Pow(26, n)) % 26 + 65)));
            }
            return retVal.ToString();
        }

Then I made changes in excel sheet.

Removed hyperlink from Table 1 and Table 3 and then again tried to populate data and hyperlink in table 2 of excel sheet. And the code works.

Please suggest how I can populate hyperlinks in table 2 of excel sheet without removing hyperlinks from table 1 and table 3.

I have already referred following suggestion from MSDN forum:

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/4651b349-ab62-404b-842a-1a19926f380c/create-a-hyperlink-to-an-existing-cell-to-another-sheet-using-open-xml-sdk?forum=oxmlsdk

Thank you


Prince Jain



Merge Rich Text ( HTML ) to Word Document Content Control using Open XML

$
0
0

Hi,

I have a word template which has a content control placeholder to hold rich text data. The data comes from a sharepoint list (rich text field) and may also include tables in it.

On checking the data from sharepoint list I found it returns me a HTML formatted data. I wish to place this data in the content placeholder with proper formatting.

For example if the data returned is HTML table ( <td> <tr> </tr><td> format) I want a table to be created with data populated. Is there any method available to place the data in content control. 

I found that third party tool ( http://html2openxml.codeplex.com/ ) is available for conversion, however this appends data to MainDocumentPart not to content control.

Please guide. Thanks in advance.


OpenXml : PowerPoint . Add an Image and a Title into a Slide

$
0
0

Hi all,
I'm using OpenXml for the first time  and  I've tried  for several days to create a simple presentation in c#.

my goal is: given a list of images as input ,create for each one a slide with a title (image name ) and the image as picture.

Currently I can create either  a slide with just a title or a slide with just the image, but I'm not able to create one with both the elements :-)

Can you help me please ?

Thanks in Advance

Davide

   


comments did not take effect

$
0
0

Hi ,

I have generate a xlsx doc with comments , but the comment did not show in the cell

the following is my xl/comments1.xml file

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><authors><author>yushang</author></authors><commentList><comment ref="B2" authorId="0"><text><r><rPr><b val="true"/></rPr><t>TEST</t></r><r><rPr><b val="true"/></rPr><t>TEST</t></r></text></comment></commentList></comments>

and xl\worksheets\_rels\Sheet1.xml.rels

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="../comments1.xml"/></Relationships>

did I miss something ?



OpenXmlReader SAX Reader appears to slow down as it gradually reads large file

$
0
0

Hi guys,

I am using the OpenXMLReader to read a large Excel file with circa 500,000 rows of 20 columns. The file size is not that big (35MB).

I am reading through all elements and gathering together data from 512 rows at a time into a List. Then after processing the data the routine continues to process the rows and get the next batch. This continues until all batches have been read.

Memory consumption is absolutely fine and when the first few batches start to be read it is reasonably fast to read a batch of 512 rows (e.g. 100-200 milliseconds). As this continues this gradually slows down to seconds and then by the end of the file it's reached about 17 seconds to read 512 rows.

Is this expected behavior because it sure came as a surprise to me? With a streaming approach I would have expected that reading the last few batches would be roughly the same as reading the first few batches.

I have added detailed logging to make sure the time is spent in the function that is parsing the elements and there really is nothing complicated going on in there. Just reading the cell values and writing the strings into a List for each row.

Is there anything I need to do to prevent this behavior? All input very welcome.

Kind regards,.

Ian

 

How to convert Powerpoint .pptx to PDF document?

$
0
0

Hi,

I am using Office Interop to convert powerpoint to pdf using save as functionality with below code. I have some issues with InterOp on some pcs where I get application is busy error.

Is it possible to convert .pptx to .pdf using open xml sdk? if yese, please provide me some sample.

      public static void ConvertPPTtoPDF(string pptFile, string pdfFile)
        {

            try
            {
                Microsoft.Office.Interop.PowerPoint.Application ppApp = new
                    Microsoft.Office.Interop.PowerPoint.Application();

                Microsoft.Office.Interop.PowerPoint.Presentation presentation = ppApp.Presentations.Open
                    (pptFile, Microsoft.Office.Core.MsoTriState.msoTrue,
                        Microsoft.Office.Core.MsoTriState.msoFalse,
                        Microsoft.Office.Core.MsoTriState.msoFalse);
                presentation.ExportAsFixedFormat(pdfFile,

                                PPT.PpFixedFormatType.ppFixedFormatTypePDF,

                                PPT.PpFixedFormatIntent.ppFixedFormatIntentPrint,

                                Microsoft.Office.Core.MsoTriState.msoFalse,

                                PPT.PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst,

                                PPT.PpPrintOutputType.ppPrintOutputSlides,

                                Microsoft.Office.Core.MsoTriState.msoFalse,

                                null,

                                PPT.PpPrintRangeType.ppPrintAll,

                                "",

                                false,

                                false,

                                false,

                                true,

                                true,

                                System.Reflection.Missing.Value);

                presentation.Close();

                presentation = null;

                ppApp = null;

                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine("exception happened while converting to PDF file..." + ex);

                throw ex;
            }

        }


VM7258

PowerPoint: Apply theme after creating PowerPoint slide

$
0
0

Hello All,

Here is my scenario:

1) Create a Power Point slide with data/charts based on the provided template.

2) After creating it the Power Point Slide should be able to adjust its layout/appearance based on the theme that it will be applied to. For e.g., if the theme doesn't have header/footer, the slide should hide it, if the theme has header/footer, the slide should display it (likewise, theme with widescreen, etc.) (I don't know if this Template or Theme that can do it).

3) Looks like I am trying to embed some script in the Open XML such that PPT engine would execute it when the theme is being applied (I don't know if this statement makes any sense at all).

Any pointer/suggestion would be greatly appreciated.

SU.


Suraj Upreti

Excel was able to open the file by repairing or removing the unreadable content

$
0
0

Hi there,

I just started using Open XML SDK and created a program to generate XLSX. It works well but the only problem is that i get a warning message while opening the xlsx and then displays the data correctly.

"Excel was able to open the file by repairing or removing the unreadable content."
"Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded."

/xl/worksheets/sheet1.xml

/xl/worksheets/sheet2.xml

I tried to windiff the xml generated xml after correction and before correction by office but in vain. I guess the problem is related to coding and could anyone please shed some light on this issue?

Thanks,

Holy

I post the code below and here is steps I do on the code.

1 .Open an XLSX file (from template with no data)

2. Set an value on a particular cell

3. Fill data on sheet1

4. Fill data on sheet2

        public Stream Create(Stream fromXlsxTemplate, IDataReader data)
        {
            if (fromXlsxTemplate == null)
            {
                throw new ArgumentNullException("fromXlsxTemplate");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            fromXlsxTemplate.Position = 0;

            // Open SpreadSheet from Resource Stream (Open XML)
            using (SpreadsheetDocument document = SpreadsheetDocument.Open(fromXlsxTemplate, true))
            {
                WorkbookPart wbPart = document.WorkbookPart;
                Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().ElementAtOrDefault(0);

                WorksheetPart wsPart =
                    (WorksheetPart)(wbPart.GetPartById(theSheet.Id));

                while (data.Read())
                {
                    WriteHeader(data, wbPart, wsPart);
                }

                data.NextResult();

                //Write to Sheet 1
                WriteSheet1(data, wsPart);

                //Move to result for sheet2
                data.NextResult();

                Sheet sheetDettaglo = wbPart.Workbook.Descendants<Sheet>().ElementAtOrDefault(1);

                WorksheetPart wsPartDet =
                    (WorksheetPart)(wbPart.GetPartById(sheetDettaglo.Id));

                //Write to Sheet 2
                WriteSheet2(data, wsPartDet);


            }

            return fromXlsxTemplate;
        }

        private void WriteHeader(IDataReader reader, WorkbookPart wbPart, WorksheetPart wsPart)
        {
            // A2 Cell
            Cell a2Cell = wsPart.Worksheet.Descendants<Cell>().
              Where(c => c.CellReference == "A2").FirstOrDefault();

            if (a2Cell != null)
            {
                string a2CellValue = a2Cell.InnerText;
                var stringTable = wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
                if (stringTable != null)
                {
                    a2CellValue = stringTable.SharedStringTable.ElementAt(int.Parse(a2CellValue)).InnerText;
                }
                a2Cell.DataType = CellValues.String;
                a2Cell.CellValue = new CellValue(string.Format(a2CellValue, DateTime.Parse(reader.GetValue(0).ToString()).ToString("dd/MM/yyyy")));

            }
        }

        private uint WriteSheet1(IDataReader reader, WorksheetPart wsPart)
        {
            SheetData sheetData = wsPart.Worksheet.GetFirstChild<SheetData>();
            uint rowIdx = 6; // Start from row 6
            while (reader.Read())
            {
                Row newRow = new Row() { RowIndex = new DocumentFormat.OpenXml.UInt32Value(rowIdx) };

                //Value fo Cell Emissioni
                Cell cell = new Cell() { StyleIndex = (UInt32Value)1U };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("Emissioni")).ToString()); //
                newRow.AppendChild(cell);

                //Value fo Cell Operazioni
                cell = new Cell() { StyleIndex = (UInt32Value)9U };
                cell.DataType = CellValues.Number;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("Operazioni")).ToString());
                newRow.AppendChild(cell);

                //Value fo Cell Totale
                cell = new Cell() { StyleIndex = (UInt32Value)9U };
                cell.DataType = CellValues.Number;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("Totale")).ToString());
                newRow.AppendChild(cell);

                sheetData.Append(newRow);
                rowIdx++;
            }
            return rowIdx;
        }

        private uint WriteSheet2(IDataReader reader, WorksheetPart wsPartDet)
        {
            uint rowIdx;
            SheetData sheetDet = wsPartDet.Worksheet.GetFirstChild<SheetData>();
            rowIdx = 2; // Start from row 2

            while (reader.Read())
            {
                Row newRow = new Row() { RowIndex = new DocumentFormat.OpenXml.UInt32Value(rowIdx) };

                //n_polizza
                Cell cell = new Cell() { };
                cell.DataType = CellValues.Number;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("n_polizza")).ToString());
                newRow.AppendChild(cell);

                //c_attivita
                cell = new Cell() { };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("c_attivita")).ToString());
                newRow.AppendChild(cell);

                //d_effetto
                cell = new Cell() { };
                cell.DataType = CellValues.Date;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("d_effetto")).ToString());
                newRow.AppendChild(cell);

                //descrizione
                cell = new Cell() { };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("descrizione")).ToString());
                newRow.AppendChild(cell);

                //tipo_liquidazione
                cell = new Cell() { };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("tipo_liquidazione")).ToString());
                newRow.AppendChild(cell);

                //d_carico
                cell = new Cell() { };
                cell.DataType = CellValues.Date;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("d_carico")).ToString());
                newRow.AppendChild(cell);

                //timestamp
                cell = new Cell() { };
                cell.DataType = CellValues.Date;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("timestamp")).ToString());
                newRow.AppendChild(cell);

                //d_assunzione
                cell = new Cell() { };
                cell.DataType = CellValues.Date;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("d_assunzione")).ToString());
                newRow.AppendChild(cell);

                //c_operazione_online
                cell = new Cell() { };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("c_operazione_online")).ToString());
                newRow.AppendChild(cell);

                //c_prodotto
                cell = new Cell() { };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("c_prodotto")).ToString());
                newRow.AppendChild(cell);

                //c_fondo 					
                cell = new Cell() { };
                cell.DataType = CellValues.Date;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("c_fondo")).ToString());
                newRow.AppendChild(cell);

                //descrizione_fondo
                cell = new Cell() { };
                cell.DataType = CellValues.Date;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("descrizione_fondo")).ToString());
                newRow.AppendChild(cell);

                //descrizione_prodotto
                cell = new Cell() { };
                cell.DataType = CellValues.Date;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("descrizione_prodotto")).ToString());
                newRow.AppendChild(cell);

                //importo
                cell = new Cell() { };
                cell.DataType = CellValues.Number;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("importo")).ToString());
                newRow.AppendChild(cell);

                //c_abi
                cell = new Cell() { };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("c_abi")).ToString());
                newRow.AppendChild(cell);

                //descrizione_lv
                cell = new Cell() { };
                cell.DataType = CellValues.String;
                cell.CellValue = new CellValue(reader.GetValue(reader.GetOrdinal("descrizione_lv")).ToString());
                newRow.AppendChild(cell);

                sheetDet.Append(newRow);
                rowIdx++;
            }
            return rowIdx;
        }

I'm having an issue with the ProofState Element and Word's Spell Check functionality

$
0
0

Is anyone aware of any OpenXML methods that would cause the ProofState attribute values to be marked as clean even when they are explicitly set to dirty? I am creating a document using OpenXML and I am setting the ProofState element as such:

internal static void MarkProofStateAsDirty( WordprocessingDocument document, MainDocumentPart docXml) { Settings settings = document.MainDocumentPart.DocumentSettingsPart.Settings; if (settings != null) { //The Settings intellisense does not contain a property for ProofState //but ProofState is 2nd element listed in XML when viewed in the Initellisense ProofState proofState = settings.GetFirstChild<ProofState>(); if (proofState != null) { proofState.Grammar = ProofingStateValues.Dirty; proofState.Spelling = ProofingStateValues.Dirty; } else {//We could not find the proofstate element, create one.

proofState = new ProofState(); proofState.Grammar = ProofingStateValues.Dirty; proofState.Spelling = ProofingStateValues.Dirty; //Zoom is the first child in the XML for the Settings object Zoom zoom = settings.GetFirstChild<Zoom>(); if (zoom != null) { settings.InsertAfter(proofState, zoom); } } } }

Prior to closing the document.Package, I validated that the proofstate attribute values are set to dirty. However, when the document is opened both the spelling and grammar attributes are set to 'clean' rather than 'dirty'. Below is a screenshot of my test document. Please note, I have the Proofing option to ‘Ignore words in UPPERCASE’ set to true so I do not expect ‘TESSST’ to be caught.

I order to recheck the spelling and grammar in the document, I can either manually update the Document properties through the Developer Tab or by using the 'Recheck Document' available in the Proofing options. This will update the text to be:   

When I create the document using OpenXML, I do not set the noProof run property to stop the run from being spell or grammar checked.

I have been able to edit the .docx file manually to set the proofState attribute values to dirty. When I open this file, I get the desired result in the second image.

Is there anything that I am missing?

Thanks!

Tony

Markup compatibility in Word documents with VML text box

$
0
0

After playing around with text boxes created in Word documents, I ended up feeling that the current situation around markup compatibility in relation to text boxes is rather confusing. Here is what I've found:

 

* Create a blank document in Word2007 and draw a text box [Insert (Ribbon tab) -> Shapes (Illustrations group) -> Text Box]. Word 2007 will use DocumentFormat.OpenXml.Vml.TextBox to wrap the text box created. See [1] later for XML code.


* Do the same in Word2010 and it will create markup compatibility content to use the newer <w:drawing> graphic frame and the older <w:pict> frame as fallback. See [2] later for XML code. In the <w:drawing> version, the OpenXML elements around the text box are Office2010 specific , including the use of DocumentFormat.OpenXml.Office2010.Word.DrawingShape.WordprocessingShape (<wps:wsp>) and DocumentFormat.OpenXml.Office2010.Word.DrawingShape.TextBoxInfo2 (<wps:txbx>).


* Do the same in Word2013 and it will create markup compatibility content similar to Word 2010, perhaps with the exception of not creating certain Office2010 specific elements (<wp14:sizeRelH> etc). See [3] later for XML code.


Now I tried using OpenXML SDK 2.5 to open the documents created above with specific markup compatibility settings, here are the results:

 

Word2007 doc with text box

      Nothing exciting here, will always load <w:pict> version with VML text box since that's the only version available.

 

Word2010 doc with text box

    MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2007

         Loads the <w:pict> (fallback) version.

    MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2010

         Loads the <w:drawing> version.

    MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2013

         Loads the <w:pict> (fallback) version. Why??

 

Word2013 doc with text box

    MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2007

         Loads the <w:pict> (fallback) version.

    MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2010

         Loads the <w:drawing> version.

    MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2013

         Loads the <w:pict> (fallback) version. Again, why??


Based on these results, I ended up with a few (rather nitpicking) discussion questions:


Why is the fallback version selected when I set TargetFileFormatVersions to Office2013 and open a Word2010 or Word2013 document? I would have thought having TargetFileFormatVersions set to Office2013 is inclusive of Office2010?


The ISO 29500-1 3rd edition spec (released in 2012) suggests DrawingML is the newer format to replace any uses of VML, but it seems the realities are different because the Word2013 document does not fully use DrawingML for text boxes (and the DrawingML code that it does use is Office2010 specific), it still includes VML text box code as the fallback case. So does this mean that while VML should be deprecated, it hasn't taken place in Word2013?


Why is TargetFileFormatVersions in the plural and FileFormatVersions a FlagsAttribute, when doing a FileFormatVersions.Office2010 | FileFormatVersions.Office2013 actually results in an exception?


The OpenXML SDK Class Library Reference (http://msdn.microsoft.com/en-us/library/office/gg278315%28v=office.15%29.aspx) includes Office2010 specific namespace (DocumentFormat.OpenXml.Office2010) and Office2013 specific namespace (DocumentFormat.OpenXml.Office15), but why is there no link to view the classes within the Office2013 namespace? Does this imply we (non-Microsoft developers) should not know about those classes? Then what about Office2010 specific classes? If we should not use Office2013 and Office2010 specific classes, does that mean we should stick with VML? So just forget about what the spec says (because it is more of an academic exercise)?


Now here is a more practical question:

 

I want to write code to process a Word2013 document with text boxes. I'm working off the ISO 29500-1 3rd edition spec right now and I don't particularly want to spend time understanding VML if I don't have to. But since opening the Word2013 file with OpenXML SDK and TargetFileFormatVersions set to Office2013 will result in the fallback VML version been used, does it mean that I should know about VMLand not worry about Microsoft dropping VML use in Word for the foreseeable future?

 

 

[1]

<w:p><w:r><w:pict><v:shapetype... >
			...</v:shapetype><v:shape... ><v:textbox><w:txbxContent><w:p>... </w:p></w:txbxContent></v:textbox></v:shape></w:pict></w:r></w:p>

[2]

<w:p ><w:r><mc:AlternateContent><mc:Choice Requires="wps"><w:drawing><wp:anchor ><wp:simplePos x="0" y="0" /><wp:extent cx="3218400" cy="2059200" /><wp:docPr id="1" name="Text Box 1" /><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"><wps:wsp><wps:cNvSpPr txBox="1" /><wps:spPr>...</wps:spPr><wps:txbx><w:txbxContent><w:p>...</w:p></w:txbxContent></wps:txbx></wps:wsp></a:graphicData></a:graphic><wp14:sizeRelH relativeFrom="margin"><wp14:pctWidth>0</wp14:pctWidth></wp14:sizeRelH><wp14:sizeRelV relativeFrom="margin"><wp14:pctHeight>0</wp14:pctHeight></wp14:sizeRelV></wp:anchor></w:drawing></mc:Choice><mc:Fallback><w:pict>
			(same as Word2007 content)</w:pict></mc:Fallback></mc:AlternateContent></w:r></w:p>

[3]

<mc:AlternateContent><mc:Choice Requires="wps"><w:drawing><wp:anchor><wp:simplePos x="0" y="0" /><wp:extent cx="3419475" cy="1114425" /><wp:docPr id="1" name="Text Box 1" /><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"><wps:wsp><wps:cNvSpPr txBox="1" /><wps:spPr>...</wps:spPr><wps:txbx><w:txbxContent><w:p>...</w:p></w:txbxContent></wps:txbx></wps:wsp></a:graphicData></a:graphic></wp:anchor></w:drawing></mc:Choice><mc:Fallback><w:pict>(same as Word2007 content)</w:pict></mc:Fallback></mc:AlternateContent>


Open XML SDK 2.5 - Excel - questions on 'internal" XML files - indentation, Byte Order Marks (BOM)

$
0
0

This post is strictly for making comparison purposes between Excel files, other than for that I don't care about the "indentation" or BOM characters.

Right now in order to compare the "original" Excel files that we currently produce (from macros) to the Excel files that I'm creating with the Open XML SDK 2.5, I'm doing the following steps:

  • Rename the existing and new Excel files from .xlsx to .zip.
  • Extracting the contents of each zip file into a new folder.
  • Open each XML file in each folder using XMLSpy, do a "pretty print", and save it.  If I don't do this step, it's pointless to do the compares.
  • Use WinDiff.exe to compare the two folders.

That works fine, other than it is labor intensive and I have 80 original files to do!

I know with the XmlWriter and other classes, there is control over the format of the xml.  I don't have the desire to switch my code to doing it that way just for the sake of comparisons.

But I don't see any formatting control (or other ways) in the SpreadsheetDocument class or other classes in the SDK.

Can someone confirm that this is correct or offer some alternatives for making these comparisons easier?

Thanks.


Unable to get PropertyDescription for customproperties

$
0
0

When we enumerate IPropertyStore interface using

PROPERTYKEY key;
hr = pps->GetAt(i, &key);

We get key for one of the custom property in xlsx document as

String from key = {D5CDD505-2E9C-101B-9397-08002B2CF9AE} 2

The custom property name given is "Test"

How to relate the key with the name of the custom property.

If I use PSGetPropertyDescription(key, IID_PPV_ARGS(&ppd));

I get Element not found error.

Is there anyway to use PS***** functions to find the name?

Thanks and regards,

R.Senthil

Excel using openxml in C#

$
0
0

hi,

How apply pivot table to the existing data in the excel sheet-1  using openxml in C#.

 

thanks,

Elangovan P

OpenXml Word , Set RTL text along with font size

$
0
0
Hey Pros,

i am trying to set a font size and right to left attrib to a word table cell text
but it always take one of them , whenever i set them both it only takes the RTL attrib
here is my code

    Paragraph p = cell.Elements<Paragraph>().First(); 

    if (p == null || p.Elements<Run>() == null || p.Elements<Run>().ToArray().Length < 1)

         p.Append(new Run());

     Run r = p.Elements<Run>().First(); 

     RunProperties RP = r.AppendChild(new RunProperties());       

     FontSize fontSize = new FontSize();  

     fontSize.Val = Fontsize.ToString(); 

     RP.AppendChild(fontSize);   

     RightToLeftText RT = new RightToLeftText()  

            {

     Val = new DocumentFormat.OpenXml.OnOffValue(true)   

            };

      RP.Append(RT); 

      if (r == null || r.Elements<Text>() == null || r.Elements<Text>().ToArray().Length < 1)     

       r.Append(new Text()); 

      Text t = r.Elements<Text>().First();

      t.Text = New.ToString();



those codes sets the text to the cell as RTL text but with standard font size
if i removed the rtl codes the font size works fine
i'v tried and searched alot with no clue
any tip would be appreciated
 
thanks in advance

Invalid Hyperlink errors when there are no hyperlinks at all

$
0
0

I'm getting "Invalid Hyperlink" errors when I try to process docx files, even though the documents have no hyperlinks at all.

I'm trying to use the DocumentFormat.OpenXml package with Mono on my OS X 10.9 Mac.  I've pulled the package straight from Nuget and I've added it as a reference in the OpenXmlPowerTools package from Eric White.  Specifically, I'm working with the HtmlConverter sub-project, but I experience the same issue in the other sub-projects that I've tried.  When I run the program on his sample files, I catch an OpenXmlPackageException just at the point of processing the document

using (WordprocessingDocument wDoc = WordprocessingDocument.Open (memoryStream, true)) { ...

The text of the exception tells me there are "Invalid Hyperlinks", but walking though the document carefully I still don't see any links, let alone invalid ones.  Just to be careful, I've use sample code I found at http://social.msdn.microsoft.com/Forums/windowsazure/en-US/8147fa29-6e55-4f4e-9d60-c07ea3779042/how-to-validate-a-word-document-using-openxml-sdk-25 to try and scrub the invalid links, but I end up with the same result.

I'm new to OpenXML and to C# so maybe there's something obvious that I'm missing, but it's looking like a bug to me.  Has anyone else experienced this and worked around it?  Have you successfully used DocumentFormat.OpenXml (or a similar package) on a Mac?

Thanks for your help


Viewing all 1288 articles
Browse latest View live


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