inserita classe x gestioen doc office XML
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
|
||||
namespace ETS_Data
|
||||
{
|
||||
/// <summary>
|
||||
/// gestioen documetni office/xml
|
||||
/// </summary>
|
||||
public class officeXmlMan
|
||||
{
|
||||
/// <summary>
|
||||
/// fa sostituzioni di testo in un doc .docx
|
||||
/// </summary>
|
||||
/// <param name="fullPathFile"></param>
|
||||
/// <param name="textOrig"></param>
|
||||
/// <param name="textNew"></param>
|
||||
public static void replaceDocxText(string fullPathFile,string textOrig, string textNew)
|
||||
{
|
||||
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fullPathFile, true))
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
|
||||
{
|
||||
string docText = sr.ReadToEnd();
|
||||
Regex regexText = new Regex(textOrig);
|
||||
docText = regexText.Replace(docText, textNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user