using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace AddStringToWord
{
public class Program
{
public static void Main(string[] args)
{
AddString("Test.docx", "你好呀");
}
public static void AddString(string filePath, string str)
{
using (WordprocessingDocument doc = WordprocessingDocument.Open(filePath, true))
{
Paragraph paragraph = new Paragraph();
Run run = new Run();
RunProperties runProperties = new RunProperties(); //属性
RunFonts fonts = new RunFonts() { EastAsia = "DFKai-SB" }; // 设置字体
FontSize size = new FontSize() { Val = "52" }; // 设置字体大小
Color color = new Color() { Val = "red" }; // 设置字体样式
// 将样式添加到属性里面
runProperties.Append(color);
runProperties.Append(size);
runProperties.Append(fonts);
run.Append(runProperties);
run.Append(new Text(str));
paragraph.Append(run);
doc.MainDocumentPart.Document.Body.Append(paragraph);
doc.MainDocumentPart.Document.Save();
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有