I would like to ask how can I print a variety of documents from C #. I did this by modifying the document word by replacing the text for example:
<Value> -> value.
I have various documents, ie. a plain text document and the document to the table. The table shows the installments to repay. Document to the table is a problem because I do not know how to retrieve data and how to display them.
The whole still must be possible to configure, add, edit, delete documents. I have somethink as You can see below.
public string CreateDoc(object fileName, string _query, string _numUmowy)
{
object oMissing = System.Reflection.Missing.Value;
object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
string message = string.Empty;
Application wordApp = new Application();
Document aDoc = null;
if (File.Exists((string)fileName))
{
DateTime today = DateTime.Now;
object readOnly = false;
object isVisible = false;
wordApp.Visible = false;
aDoc = wordApp.Documents.Open(ref fileName, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
aDoc.Activate();
using (SQLiteConnection conn = new SQLiteConnection(GetConnStr()))
{
using (SQLiteCommand cmd = new SQLiteCommand(_query, conn))
{
conn.Open();
cmd.Parameters.AddWithValue("@UmowaNum", _numUmowy);
using (SQLiteDataReader rdr = cmd.ExecuteReader())
{
if (rdr.HasRows)
{
rdr.Read();
int rdrLength = rdr.FieldCount;
for (int i = 0; i < rdrLength; i++)
{
this.FindAndReplace(wordApp, "<" + rdr.GetName(i) + ">", rdr[i].ToString());
}
aDoc.PrintOut(oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing);
message = "Drukowanie zakończone powodzeniem!";
}
}
}
}
aDoc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
wordApp.Quit();
return message;
}
else
{
message = "Plik nie istnieje!";
return message;
}
}
This code print Agreement, but I don't know how to print Installment. Agreement.doc
aa bbb fbdsf
<Value1>
aa bbb fbdsf
<Value2>
aa bbb fbdsf
<Value3>
aa bbb fbdsf
<Value4>
aa bbb fbdsf
<Value5>
Installment.doc
aa bbb fbdsf
<Value1>
aa bbb fbdsf
<Value2>
aa bbb fbdsf
TABLE (start)
1. <val1.1> <val1.2> <val1.3>
2. <val2.1> <val2.2> <val2.3>
3. <val3.1> <val3.2> <val3.3>
4. <val4.1> <val4.2> <val4.3>
5. <val5.1> <val5.2> <val5.3>
TABLE (end)