NPOI是一个免费开源的开源可以不用在电脑端安装office并操作excel word文件的插件 安装方法不赘述 只讲干货
调用方法
RemoveParagraph("D:\\桌面\\123.docx",0);//删除第一行
代码:
/// <summary>
/// Npoi Word删除指定段落
/// </summary>
/// <param name="fileName">word全文件路径</param>
/// <param name="ParagraphIndex">指定的段落</param>
public void RemoveParagraph(string fileName, int ParagraphIndex)
{
FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
XWPFDocument doc = new XWPFDocument(fs);
doc.RemoveBodyElement(ParagraphIndex);
FileStream outPut = new FileStream(fileName, FileMode.Create);
doc.Write(outPut);//写入文件
fs.Close(); fs.Dispose();//释放资源
outPut.Close(); outPut.Dispose();
}
本文暂时没有评论,来添加一个吧(●'◡'●)