none
insert multiple images into a excel sheet using OPENXML RRS feed

Answers

  • Hi abdessamad,

    Thanks for posting in the MSDN Forum.

    As far as I know DataBar isn't a image in the Excel document. Image will insert into shape's range. If you want to create DataBar following snippet might help you.

    using DocumentFormat.OpenXml.Spreadsheet;
    using DocumentFormat.OpenXml;
    using X14 = DocumentFormat.OpenXml.Office2010.Excel;
    using Excel = DocumentFormat.OpenXml.Office.Excel;
    
    namespace GeneratedCode
    {
        public class GeneratedClass
        {
            // Creates an WorksheetExtensionList instance and adds its children.
            public WorksheetExtensionList GenerateWorksheetExtensionList()
            {
                WorksheetExtensionList worksheetExtensionList1 = new WorksheetExtensionList();
    
                WorksheetExtension worksheetExtension1 = new WorksheetExtension(){ Uri = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}" };
                worksheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
    
                X14.ConditionalFormattings conditionalFormattings1 = new X14.ConditionalFormattings();
    
                X14.ConditionalFormatting conditionalFormatting1 = new X14.ConditionalFormatting();
                conditionalFormatting1.AddNamespaceDeclaration("xm", "http://schemas.microsoft.com/office/excel/2006/main");
    
                X14.ConditionalFormattingRule conditionalFormattingRule1 = new X14.ConditionalFormattingRule(){ Type = ConditionalFormatValues.DataBar, Id = "{6096AB47-D69D-45EF-915F-20369113BEF5}" };
    
                X14.DataBar dataBar1 = new X14.DataBar(){ MinLength = (UInt32Value)0U, MaxLength = (UInt32Value)100U, Border = true, NegativeBarBorderColorSameAsPositive = false };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject1 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMin };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject2 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMax };
                X14.BorderColor borderColor1 = new X14.BorderColor(){ Rgb = "FF008AEF" };
                X14.NegativeFillColor negativeFillColor1 = new X14.NegativeFillColor(){ Rgb = "FFFF0000" };
                X14.NegativeBorderColor negativeBorderColor1 = new X14.NegativeBorderColor(){ Rgb = "FFFF0000" };
                X14.BarAxisColor barAxisColor1 = new X14.BarAxisColor(){ Rgb = "FF000000" };
    
                dataBar1.Append(conditionalFormattingValueObject1);
                dataBar1.Append(conditionalFormattingValueObject2);
                dataBar1.Append(borderColor1);
                dataBar1.Append(negativeFillColor1);
                dataBar1.Append(negativeBorderColor1);
                dataBar1.Append(barAxisColor1);
    
                conditionalFormattingRule1.Append(dataBar1);
                Excel.ReferenceSequence referenceSequence1 = new Excel.ReferenceSequence();
                referenceSequence1.Text = "A3";
    
                conditionalFormatting1.Append(conditionalFormattingRule1);
                conditionalFormatting1.Append(referenceSequence1);
    
                X14.ConditionalFormatting conditionalFormatting2 = new X14.ConditionalFormatting();
                conditionalFormatting2.AddNamespaceDeclaration("xm", "http://schemas.microsoft.com/office/excel/2006/main");
    
                X14.ConditionalFormattingRule conditionalFormattingRule2 = new X14.ConditionalFormattingRule(){ Type = ConditionalFormatValues.DataBar, Id = "{1609DA18-53EB-4973-8F67-F0CA48926F35}" };
    
                X14.DataBar dataBar2 = new X14.DataBar(){ MinLength = (UInt32Value)0U, MaxLength = (UInt32Value)100U, Border = true, NegativeBarBorderColorSameAsPositive = false };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject3 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMin };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject4 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMax };
                X14.BorderColor borderColor2 = new X14.BorderColor(){ Rgb = "FF008AEF" };
                X14.NegativeFillColor negativeFillColor2 = new X14.NegativeFillColor(){ Rgb = "FFFF0000" };
                X14.NegativeBorderColor negativeBorderColor2 = new X14.NegativeBorderColor(){ Rgb = "FFFF0000" };
                X14.BarAxisColor barAxisColor2 = new X14.BarAxisColor(){ Rgb = "FF000000" };
    
                dataBar2.Append(conditionalFormattingValueObject3);
                dataBar2.Append(conditionalFormattingValueObject4);
                dataBar2.Append(borderColor2);
                dataBar2.Append(negativeFillColor2);
                dataBar2.Append(negativeBorderColor2);
                dataBar2.Append(barAxisColor2);
    
                conditionalFormattingRule2.Append(dataBar2);
                Excel.ReferenceSequence referenceSequence2 = new Excel.ReferenceSequence();
                referenceSequence2.Text = "A1:A7";
    
                conditionalFormatting2.Append(conditionalFormattingRule2);
                conditionalFormatting2.Append(referenceSequence2);
    
                conditionalFormattings1.Append(conditionalFormatting1);
                conditionalFormattings1.Append(conditionalFormatting2);
    
                worksheetExtension1.Append(conditionalFormattings1);
    
                worksheetExtensionList1.Append(worksheetExtension1);
                return worksheetExtensionList1;
            }
    
    
        }
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 4, 2012 6:04 AM
    Moderator
  • Hi server_2010,

    You can use GenerateWorksheetExtensionList() method in your code.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 11, 2012 7:25 AM
    Moderator

All replies

  • Hi abdessamad,

    Thanks for posting in the MSDN Forum.

    As far as I know DataBar isn't a image in the Excel document. Image will insert into shape's range. If you want to create DataBar following snippet might help you.

    using DocumentFormat.OpenXml.Spreadsheet;
    using DocumentFormat.OpenXml;
    using X14 = DocumentFormat.OpenXml.Office2010.Excel;
    using Excel = DocumentFormat.OpenXml.Office.Excel;
    
    namespace GeneratedCode
    {
        public class GeneratedClass
        {
            // Creates an WorksheetExtensionList instance and adds its children.
            public WorksheetExtensionList GenerateWorksheetExtensionList()
            {
                WorksheetExtensionList worksheetExtensionList1 = new WorksheetExtensionList();
    
                WorksheetExtension worksheetExtension1 = new WorksheetExtension(){ Uri = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}" };
                worksheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
    
                X14.ConditionalFormattings conditionalFormattings1 = new X14.ConditionalFormattings();
    
                X14.ConditionalFormatting conditionalFormatting1 = new X14.ConditionalFormatting();
                conditionalFormatting1.AddNamespaceDeclaration("xm", "http://schemas.microsoft.com/office/excel/2006/main");
    
                X14.ConditionalFormattingRule conditionalFormattingRule1 = new X14.ConditionalFormattingRule(){ Type = ConditionalFormatValues.DataBar, Id = "{6096AB47-D69D-45EF-915F-20369113BEF5}" };
    
                X14.DataBar dataBar1 = new X14.DataBar(){ MinLength = (UInt32Value)0U, MaxLength = (UInt32Value)100U, Border = true, NegativeBarBorderColorSameAsPositive = false };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject1 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMin };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject2 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMax };
                X14.BorderColor borderColor1 = new X14.BorderColor(){ Rgb = "FF008AEF" };
                X14.NegativeFillColor negativeFillColor1 = new X14.NegativeFillColor(){ Rgb = "FFFF0000" };
                X14.NegativeBorderColor negativeBorderColor1 = new X14.NegativeBorderColor(){ Rgb = "FFFF0000" };
                X14.BarAxisColor barAxisColor1 = new X14.BarAxisColor(){ Rgb = "FF000000" };
    
                dataBar1.Append(conditionalFormattingValueObject1);
                dataBar1.Append(conditionalFormattingValueObject2);
                dataBar1.Append(borderColor1);
                dataBar1.Append(negativeFillColor1);
                dataBar1.Append(negativeBorderColor1);
                dataBar1.Append(barAxisColor1);
    
                conditionalFormattingRule1.Append(dataBar1);
                Excel.ReferenceSequence referenceSequence1 = new Excel.ReferenceSequence();
                referenceSequence1.Text = "A3";
    
                conditionalFormatting1.Append(conditionalFormattingRule1);
                conditionalFormatting1.Append(referenceSequence1);
    
                X14.ConditionalFormatting conditionalFormatting2 = new X14.ConditionalFormatting();
                conditionalFormatting2.AddNamespaceDeclaration("xm", "http://schemas.microsoft.com/office/excel/2006/main");
    
                X14.ConditionalFormattingRule conditionalFormattingRule2 = new X14.ConditionalFormattingRule(){ Type = ConditionalFormatValues.DataBar, Id = "{1609DA18-53EB-4973-8F67-F0CA48926F35}" };
    
                X14.DataBar dataBar2 = new X14.DataBar(){ MinLength = (UInt32Value)0U, MaxLength = (UInt32Value)100U, Border = true, NegativeBarBorderColorSameAsPositive = false };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject3 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMin };
                X14.ConditionalFormattingValueObject conditionalFormattingValueObject4 = new X14.ConditionalFormattingValueObject(){ Type = X14.ConditionalFormattingValueObjectTypeValues.AutoMax };
                X14.BorderColor borderColor2 = new X14.BorderColor(){ Rgb = "FF008AEF" };
                X14.NegativeFillColor negativeFillColor2 = new X14.NegativeFillColor(){ Rgb = "FFFF0000" };
                X14.NegativeBorderColor negativeBorderColor2 = new X14.NegativeBorderColor(){ Rgb = "FFFF0000" };
                X14.BarAxisColor barAxisColor2 = new X14.BarAxisColor(){ Rgb = "FF000000" };
    
                dataBar2.Append(conditionalFormattingValueObject3);
                dataBar2.Append(conditionalFormattingValueObject4);
                dataBar2.Append(borderColor2);
                dataBar2.Append(negativeFillColor2);
                dataBar2.Append(negativeBorderColor2);
                dataBar2.Append(barAxisColor2);
    
                conditionalFormattingRule2.Append(dataBar2);
                Excel.ReferenceSequence referenceSequence2 = new Excel.ReferenceSequence();
                referenceSequence2.Text = "A1:A7";
    
                conditionalFormatting2.Append(conditionalFormattingRule2);
                conditionalFormatting2.Append(referenceSequence2);
    
                conditionalFormattings1.Append(conditionalFormatting1);
                conditionalFormattings1.Append(conditionalFormatting2);
    
                worksheetExtension1.Append(conditionalFormattings1);
    
                worksheetExtensionList1.Append(worksheetExtension1);
                return worksheetExtensionList1;
            }
    
    
        }
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 4, 2012 6:04 AM
    Moderator
  • Hi Tom,

    thank you for your reply. I am newbie in OpenXML. can you please help me how to use your code in mine. where can I call the class?

    thank you very much.

    Abdessamad

    Wednesday, July 4, 2012 8:22 AM
  • Hi server_2010,

    You can use GenerateWorksheetExtensionList() method in your code.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 11, 2012 7:25 AM
    Moderator