开发者

OpenXML Sdk VML Set CheckBox Checked

ControlPropertiesPart c2 = util.getCheckBoxByLabel(worksheetPart, "ENV"); 
c2.FormControlProperties.Checked = DocumentFormat.OpenXml.Office2010.Excel.CheckedValues.Checked; 
worksheetPart.Worksheet.Save(); 

Where I have to checked a checkbox inside a vmlDrawing in my spreadsheet document.

The code is perfect开发者_Python百科 with Office 2010 but using Office 2007 when i open the document the checkbox isn't checked.

How to do it?


From what I read in the documentation ControlPropertiesPart is only defined for Office 2010, so 2007 will ignore it.

you can edit manually (text edit, not using OpenXML API the file vmlDrawingPart1.xml

you can find the check boxes in the document are in this form:

<x:ClientData ObjectType="Checkbox">
   <x:SizeWithCells/>
   <x:Anchor>
    6, 38, 17, 15, 8, 89, 18, 12</x:Anchor>
   <x:AutoFill>False</x:AutoFill>
   <x:AutoLine>False</x:AutoLine>
   <x:TextVAlign>Center</x:TextVAlign>

   <x:NoThreeD/>
  </x:ClientData>

if you want to check them simply add

<x:Checked>1</x:Checked>

as a sub tag of x:ClientData

I did it using c# like so:

VmlDrawingPart vmlDrawingPart1 = part.GetPartById("rId8") as VmlDrawingPart;
GenerateVmlDrawingPart1Content(vmlDrawingPart1);


private void GenerateVmlDrawingPart1Content(VmlDrawingPart vmlDrawingPart1)
{
        System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(vmlDrawingPart1.GetStream(System.IO.FileMode.OpenOrCreate), System.Text.Encoding.UTF8);
        writer.WriteRaw(vml2007);
        writer.Flush();
        writer.Close();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜