Mam DateTable
. Trzeba wstawić go zamiast jakiegoś zestawu znaków w dokumencie teplate.Jak wstawić tabelę do dokumentu programu Word zamiast znacznika tekstowego?
mogę zamienić tekst na tekst w ten sposób (dużo missingObj aby uniknąć błędów):
using Word = Microsoft.Office.Interop.Word;
Word._Application application;
Word._Document document;
Object missingObj = System.Reflection.Missing.Value;
Object trueObj = true;
Object falseObj = false;
private void create_button1_Click(object sender, EventArgs e) {
application = new Word.Application();
Object templatePathObj;
templatePathObj = "template.dot";
try {
document = application.Documents.Add(ref templatePathObj,
ref missingObj, ref missingObj, ref missingObj);
}
catch (Exception error) {
document.Close(ref falseObj, ref missingObj, ref missingObj);
application.Quit(ref missingObj, ref missingObj, ref missingObj);
document = null;
application = null;
throw error;
}
object strToFindObj = "%%mark%%";
object replaceStrObj = "text to replace";
Word.Range wordRange;
object replaceTypeObj;
replaceTypeObj = Word.WdReplace.wdReplaceAll;
for (int i = 1; i <= document.Sections.Count; i++) {
wordRange = document.Sections[i].Range;
Word.Find wordFindObj = wordRange.Find;
object[] wordFindParameters = new object[15] { strToFindObj, missingObj,
missingObj, missingObj, missingObj, missingObj, missingObj, missingObj,
missingObj, replaceStrObj, replaceTypeObj, missingObj, missingObj,
missingObj, missingObj };
wordFindObj.GetType().InvokeMember("Execute", BindingFlags.InvokeMethod,
null, wordFindObj, wordFindParameters);
}
application.Visible = true;
}
Co muszę zmienić, więc ten kod odbędzie DataTable
zamiast strToFindObj
?
W tym przykładzie mogę wymienić rzeczy w Range
, co jest pewne fragmen dokumentu w tym tabele, format, itp