none
How to set text orientation in the cell RRS feed

  • Question

  • Hello.

    Is it possible to set text orientation in the cell through OpenXML and without Interop? I dont want to open exel file after generating, I just want to insert data with formatting

    I want to rotate text 90 degress?

    How can I do that?

    Monday, June 11, 2012 8:10 AM

Answers

  • Hi,

    By OpenXml SDK Productivity Tool, I reflect code for a workbook which contains a 59 degree rotated cell:

    This piece of code should help:

    Alignment alignment1 = new Alignment(){ TextRotation = (UInt32Value)59U };

    Complete function below:

     // Generates content of workbookStylesPart1.
            private void GenerateWorkbookStylesPart1Content(WorkbookStylesPart workbookStylesPart1)
            {
                Stylesheet stylesheet1 = new Stylesheet(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "x14ac" }  };
                stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
                stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
                Fonts fonts1 = new Fonts(){ Count = (UInt32Value)1U, KnownFonts = true };
                Font font1 = new Font();
                FontSize fontSize1 = new FontSize(){ Val = 11D };
                Color color1 = new Color(){ Theme = (UInt32Value)1U };
                FontName fontName1 = new FontName(){ Val = "Calibri" };
                FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering(){ Val = 2 };
                FontScheme fontScheme1 = new FontScheme(){ Val = FontSchemeValues.Minor };
                font1.Append(fontSize1);
                font1.Append(color1);
                font1.Append(fontName1);
                font1.Append(fontFamilyNumbering1);
                font1.Append(fontScheme1);
                fonts1.Append(font1);
                Fills fills1 = new Fills(){ Count = (UInt32Value)2U };
                Fill fill1 = new Fill();
                PatternFill patternFill1 = new PatternFill(){ PatternType = PatternValues.None };
                fill1.Append(patternFill1);
                Fill fill2 = new Fill();
                PatternFill patternFill2 = new PatternFill(){ PatternType = PatternValues.Gray125 };
                fill2.Append(patternFill2);
                fills1.Append(fill1);
                fills1.Append(fill2);
                Borders borders1 = new Borders(){ Count = (UInt32Value)1U };
                Border border1 = new Border();
                LeftBorder leftBorder1 = new LeftBorder();
                RightBorder rightBorder1 = new RightBorder();
                TopBorder topBorder1 = new TopBorder();
                BottomBorder bottomBorder1 = new BottomBorder();
                DiagonalBorder diagonalBorder1 = new DiagonalBorder();
                border1.Append(leftBorder1);
                border1.Append(rightBorder1);
                border1.Append(topBorder1);
                border1.Append(bottomBorder1);
                border1.Append(diagonalBorder1);
                borders1.Append(border1);
                CellStyleFormats cellStyleFormats1 = new CellStyleFormats(){ Count = (UInt32Value)1U };
                CellFormat cellFormat1 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U };
                cellStyleFormats1.Append(cellFormat1);
                CellFormats cellFormats1 = new CellFormats(){ Count = (UInt32Value)2U };
                CellFormat cellFormat2 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U };
                CellFormat cellFormat3 = new CellFormat(){ NumberFormatId = (UInt32Value)3U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyAlignment = true };
                Alignment alignment1 = new Alignment(){ TextRotation = (UInt32Value)59U };
                cellFormat3.Append(alignment1);
                cellFormats1.Append(cellFormat2);
                cellFormats1.Append(cellFormat3);
                CellStyles cellStyles1 = new CellStyles(){ Count = (UInt32Value)1U };
                CellStyle cellStyle1 = new CellStyle(){ Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U };
                cellStyles1.Append(cellStyle1);
                DifferentialFormats differentialFormats1 = new DifferentialFormats(){ Count = (UInt32Value)0U };
                TableStyles tableStyles1 = new TableStyles(){ Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" };
                StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList();
                StylesheetExtension stylesheetExtension1 = new StylesheetExtension(){ Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
                stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
                X14.SlicerStyles slicerStyles1 = new X14.SlicerStyles(){ DefaultSlicerStyle = "SlicerStyleLight1" };
                stylesheetExtension1.Append(slicerStyles1);
                stylesheetExtensionList1.Append(stylesheetExtension1);
                stylesheet1.Append(fonts1);
                stylesheet1.Append(fills1);
                stylesheet1.Append(borders1);
                stylesheet1.Append(cellStyleFormats1);
                stylesheet1.Append(cellFormats1);
                stylesheet1.Append(cellStyles1);
                stylesheet1.Append(differentialFormats1);
                stylesheet1.Append(tableStyles1);
                stylesheet1.Append(stylesheetExtensionList1);
                workbookStylesPart1.Stylesheet = stylesheet1;
            }


    Forrest Guo | MSDN Community Support | Feedback to manager

    Tuesday, June 12, 2012 7:23 AM
    Moderator