marspd
Forum Replies Created
-
AuthorPosts
-
June 21, 2016 at 10:24 am in reply to: How to access a FormControl checkbox in an Excel sheet using OpenXML SDK #3515
Hi Eric
Thank you so much for the reply.
I did indeed find those screen casts of yours (Excellent by the way) and realised what I needed to do as you have pointed out above. I’m currently doing that at the moment.
If I can possibly ask you another question on the same topic though I would very much appreciate it?
Using OpenXML I have this bit of code to get a list of all the form controls and whether they are checked or not
foreach (var ctrl in sheetPart.ControlPropertiesParts) { string ctrlId = sheetPart.GetIdOfPart(ctrl); Console.Write($"Ctrl Id:{ctrlId} "); if (ctrl.FormControlProperties.Checked != null) Console.Write("Checked"); Console.WriteLine(); }
and this bit of code to get all the AlternateContent which gives me the locations of all the form controls.
foreach (var altContent in sheetPart.DrawingsPart.WorksheetDrawing.OfType<DocumentFormat.OpenXml.AlternateContent>()) { DocumentFormat.OpenXml.AlternateContentChoice child = altContent.OfType<DocumentFormat.OpenXml.AlternateContentChoice>().FirstOrDefault(); if (child != null) { var loc = child.OfType<TwoCellAnchor>().FirstOrDefault(); if (loc != null) { var shp = loc.OfType<Shape>().FirstOrDefault(); if (shp != null) { var shpProp = shp.OfType<NonVisualShapeProperties>().FirstOrDefault(); var dwgProp = shpProp.OfType<NonVisualDrawingProperties>().FirstOrDefault(); Console.WriteLine($"Shape Id:{dwgProp.Id} Name:{dwgProp.Name}"); } var frm = loc.OfType<FromMarker>().FirstOrDefault(); var to = loc.OfType<ToMarker>().FirstOrDefault(); if (frm != null && to != null) { int frmCol = int.Parse(frm.ColumnId.Text); int frmColOff = int.Parse(frm.ColumnOffset.Text); int frmRow = int.Parse(frm.RowId.Text); int frmRowOff = int.Parse(frm.RowOffset.Text); int toCol = int.Parse(to.ColumnId.Text); int toColOff = int.Parse(to.ColumnOffset.Text); int toRow = int.Parse(to.RowId.Text); int toRowOff = int.Parse(to.RowOffset.Text); Console.WriteLine($"From Col:{frmCol}:{frmColOff} Row:{frmRow}:{frmRowOff}"); Console.WriteLine($"To Col:{toCol}:{toColOff} Row:{toRow}:{toRowOff}"); } } } }
However, I can’t see anywhere that links the two lists together. I don’t know which form control relates to which AlternateContent control.
If I look at the raw Xml I can see the relationship Id’s that link them but I can’t see these relationship Id’s in any of the properties of any of the objects in OpenXML that I am dealing with.
Can you point me in the right direction by any chance?
Regards
Paul- This reply was modified 8 years, 4 months ago by marspd.
-
AuthorPosts