janjel
Yeni bir Steve doğdu!
- Katılım
- 1 Ekim 2018
- Mesajlar
- 46
- Tepki puanı
- 28
- Puanları
- 0
valla çok işe yarar header kısımlarındaki metinleride değiştiriyor
C#:
public class replaceModel
{
public replaceModel(string find,string replace)
{
this.replace = replace;
this.find = find;
}
public string find;
public string replace;
}
public static string replaceAndGetFileName(string baseFileName, string baseFileDir, string copyToDir, List<replaceModel> replaceList)
{
string rnd = Siniflar.genelAPI.generateRandomString(35);
string sourceFile = System.IO.Path.Combine(baseFileDir, baseFileName);
string destFileWord = System.IO.Path.Combine(copyToDir, rnd + ".docx");
File.Copy(sourceFile, destFileWord, true);
using (WordprocessingDocument wDoc = WordprocessingDocument.Open(destFileWord, true))
{
XDocument xDoc = wDoc.MainDocumentPart.GetXDocument();
IEnumerable<XElement> contentz = xDoc.Descendants(W.p);
foreach (var item in replaceList)
{
OpenXmlRegex.Replace(contentz, new Regex(item.find), item.replace, null);
}
wDoc.MainDocumentPart.PutXDocument();
foreach (var item in wDoc.MainDocumentPart.HeaderParts)
{
IEnumerable<XElement> contenty = item.GetXDocument().Descendants(W.p);
foreach (var itemx in replaceList)
{
OpenXmlRegex.Replace(contenty, new Regex(itemx.find), itemx.replace, null);
}
item.PutXDocument();
}
}
}