c# - Create Two Tables Side by Side in Open XML Word Document -
i can create 2 tables easy plenty having problem getting them appear side side this:
i unsure how accomplish using open xml sdk. i'm guessing either tableproperty or trick paragraphs using productivity tool couldn't work out. code snippet:
int leftwidth = 2000; int rightwidth = 2000; int numberofcols = 2; table lefttable = starttable(numberofcols, leftwidth); // create basic table table righttable = starttable(numberofcols, rightwidth); body.append(lefttable); /// right table properties here? body.append(righttable); i open different methods, although ideally thought transferable 3 tables side side too.
in end realised there 2 main ways accomplish word - either click table , drag it's top left crosshair want or split page 2 columns , place column break between tables.
floating tables method
int leftwidth = 2000; int rightwidth = 2000; int numberofcols = 2; table lefttable = starttable(numberofcols, leftwidth); // create basic table table righttable = starttable(numberofcols, rightwidth); /// add together table position properties , place table in top left tableproperties tblprops = lefttable.descendants<tableproperties>().first(); tablepositionproperties tblpos = new tablepositionproperties() { verticalanchor = verticalanchorvalues.text, tablepositiony = 1 }; tableoverlap overlap = new tableoverlap() { val = tableoverlapvalues.overlap }; tblprops.append(tblpos, overlap); body.append(lefttable); /// add together position property right table, set 8700 , 2400 want table tableproperties tblprops2 = righttable.descendants<tableproperties>().first(); tablepositionproperties tblpos2 = new tablepositionproperties() { horizontalanchor = horizontalanchorvalues.page, verticalanchor = verticalanchorvalues.page, tablepositionx = 8700, tablepositiony = 2400 }; tableoverlap overlap2 = new tableoverlap() { val = tableoverlapvalues.overlap }; tblprops2.append(tblpos2, overlap2); body.append(righttable); columns method
before tables place code maintain prior content in 1 column:
/// create sure else stays @ 1 column paragraph onecolpara = body.appendchild(new paragraph()); /// adjust current doc properties maintain things landscape sectionproperties sectiononeprops = null; if (body.descendants<sectionproperties>().count() > 0) sectiononeprops = (sectionproperties)body.descendants<sectionproperties>().first().clonenode(true); else sectiononeprops = new sectionproperties(); sectiononeprops.removeallchildren<columns>(); sectiononeprops.removeallchildren<docgrid>(); sectiononeprops.append(new columns(){ space = "708" }, new docgrid(){ linepitch = 360 }, new sectiontype { val = sectionmarkvalues.continuous } ); onecolpara.append(new paragraphproperties(sectiononeprops)); then in tables part:
int leftwidth = 2000; int rightwidth = 2000; int numberofcols = 2; table lefttable = starttable(numberofcols, leftwidth); // create basic table table righttable = starttable(numberofcols, rightwidth); /// need blank para line tables body.append(new paragraph()); body.append(lefttable); /// place tables side side body.append(new paragraph(new run(new break() { type = breakvalues.column }))); body.append(righttable); /// create section have 2 columns paragraph twocolpara = body.appendchild(new paragraph()); /// adjust current doc properties maintain things landscape sectionproperties sectiontwoprops = null; if (body.descendants<sectionproperties>().count() > 0) sectiontwoprops = (sectionproperties)body.descendants<sectionproperties>().first().clonenode(true); else sectiontwoprops = new sectionproperties(); sectiontwoprops.removeallchildren<columns>(); sectiontwoprops.removeallchildren<docgrid>(); sectiontwoprops.append(new columns() { space = "284", columncount = 2 }, new docgrid() { linepitch = 360 }, new sectiontype { val = sectionmarkvalues.continuous }); twocolpara.append(new paragraphproperties(sectiontwoprops)); c# .net openxml openxml-sdk
No comments:
Post a Comment