0

我想在 C# 中使用 Open XML SDK 创建一定数量的复选框。我该怎么做?

例子:

(Checkbox) - Shoes 

(Checkbox) - Shirt

复选框数量也有所不同。我正在阅读模板文档,然后进行编辑以返回。到目前为止,我有这样的事情:

string documentText;
using (StreamReader reader ...)
{
    documentText = reader.ReadToEnd();
}

string addClothes = "";
Run newCheckBox = GenerateRun();
foreach(var item in ClothesList)
{
    addClothes = item.clothing;
    //MY DILEMMA
    documentText = documentText.Replace("##clothing##", newCheckBox + addClothes + "NewLine");
}


public Run GenerateRun()
{
    Run run1 = new Run() { RsidRunProperties = "004C0D9A", RsidRunAddition = "00850FA5" };
    FieldCode fieldCode1 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve };
    fieldCode1.Text = " FORMCHECKBOX ";

    run1.Append(fieldCode1);
    return run1;
}
4

1 回答 1

0

使用 OpenXML SDK 我认为它是这样的:(原始复制/粘贴 - 的值-1636166143可能会偏离)

using w14 = DocumentFormat.OpenXml.Office2010.Word

            SdtRun sdtRun1 = new SdtRun();

            SdtProperties sdtProperties1 = new SdtProperties();
            SdtId sdtId1 = new SdtId(){ Val = -1636166143 };

            W14.SdtContentCheckBox sdtContentCheckBox1 = new W14.SdtContentCheckBox();
            W14.Checked checked1 = new W14.Checked(){ Val = W14.OnOffValues.Zero };
            W14.CheckedState checkedState1 = new W14.CheckedState(){ Font = "MS Gothic", Val = "2612" };
            W14.UncheckedState uncheckedState1 = new W14.UncheckedState(){ Font = "MS Gothic", Val = "2610" };

            sdtContentCheckBox1.Append(checked1);
            sdtContentCheckBox1.Append(checkedState1);
            sdtContentCheckBox1.Append(uncheckedState1);

            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtContentCheckBox1);

            SdtContentRun sdtContentRun1 = new SdtContentRun();

            Run run1 = new Run();

            RunProperties runProperties1 = new RunProperties();
            RunFonts runFonts1 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia, Ascii = "MS Gothic", HighAnsi = "MS Gothic", EastAsia = "MS Gothic" };

            runProperties1.Append(runFonts1);
            Text text1 = new Text();
            text1.Text = "☐";

            run1.Append(runProperties1);
            run1.Append(text1);

            sdtContentRun1.Append(run1);

复选框后面的任何文本都在上面的代码之后

于 2013-02-12T19:44:51.647 回答