Ejemplo n.º 1
0
        /// <summary>
        /// 添加单文本段 多文本内容 (多样式)
        /// </summary>
        /// <param name="model">多文本内容对象模型</param>
        public void AddTextParagraphWithMultiText(OneParagraphMultiTextModel model)
        {
            if (model == null || model.TextModels.Count < 1)
            {
                throw new ArgumentException(nameof(model));
            }
            XWPFParagraph paragraph = document.CreateParagraph();   // 创建段落对象
            int           idx       = 1;

            foreach (var text in model.TextModels)
            {
                SetText(text.Content, paragraph, text.TextOptions);

                if (idx < model.TextModels.Count)
                {
                    SetText(model.Separator, paragraph);
                }

                document.SetParagraph(paragraph, posParagraph);
                idx++;
            }
            posParagraph++;
        }
Ejemplo n.º 2
0
        private static OneParagraphMultiTextModel GetOneParagraphMultiTextModelFakeData()
        {
            TextOptions textOption1 = new TextOptions
            {
                FontStyle = new Word.Styles.FontStyle {
                    ForeColor = "FF00FF"
                }
            };
            TextOptions textOption2 = new TextOptions
            {
                FontStyle = new Word.Styles.FontStyle {
                    ForeColor = "FFD700"
                }
            };
            TextOptions textOption3 = new TextOptions
            {
                FontStyle = new Word.Styles.FontStyle {
                    ForeColor = "0000CD"
                }
            };
            OneParagraphMultiTextModel model      = new OneParagraphMultiTextModel();
            List <TextModel>           textModels = new List <TextModel>();

            textModels.Add(new TextModel {
                Content = "单段落多文本段多样式1", TextOptions = textOption1
            });
            textModels.Add(new TextModel {
                Content = "单段落多文本段多样式2", TextOptions = textOption2
            });
            textModels.Add(new TextModel {
                Content = "单段落多文本段多样式3", TextOptions = textOption3
            });
            model.Separator  = "    |    ";
            model.TextModels = textModels;
            return(model);
        }