I have succesfully converted an app that was using Microsoft Word to
using XML, which is much more robust. However, it would be nice if I
could emulate this - which wokred nicely with Word, inserting a table
of data after a bookmark:

QuoteItem qi = new QuoteItem();
                qi.QuoteJobID = Convert.ToInt32(jobID);
                DataTable dtQuoteItems = qi.getQuoteItemsForJobID();
                int noOfItems = dtQuoteItems.Rows.Count;
                if (noOfItems > 0)
                {
                    Word.Table oTable;
                    Word.Range wrdRange =
oWordDoc.Bookmarks.get_Item(ref oBookMarkName).Range;


                    //Word.Range wrdRng =
oWordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    int NumRows = noOfItems + 1;
                    int NumColumns = 3;
                    oTable = oWordDoc.Tables.Add(wrdRange, NumRows,
NumColumns, ref oMissing, ref oMissing);
                    oTable.Range.ParagraphFormat.SpaceAfter = 6;
                    // table headings
                    oTable.Cell(1, 1).Range.Text = "ITEM";
                    oTable.Cell(1, 2).Range.Text = "DESCRIPTION";
                    oTable.Cell(1, 3).Range.Text = "COST";


                    int r;
                    //string strText;
                    for (r = 2; r <= noOfItems + 1; r++)
                    //for (c = 1; c <= 3; c++)
                    {
                        int actCount = r - 1;
                        int dumCount = r - 2;
                        DataRow row = dtQuoteItems.Rows[dumCount];


                        oTable.Cell(r, 1).Range.Text =
actCount.ToString();
                        oTable.Cell(r, 2).Range.Text =
row["QuoteItemDescription"].ToString();
                        oTable.Cell(r, 3).Range.Text =
String.Format("{0:c}", row["QuoteItemCost"]);
                    }
                    oTable.Rows[1].Range.Font.Bold = 1;
                    oTable.Rows[1].Range.Font.Italic = 1;
                    oTable.Columns[1].Width =
oWord.InchesToPoints(1);
                    //Change width of columns 1 & 2
                    oTable.Columns[2].Width =
oWord.InchesToPoints(4);
                    oTable.Columns[3].Width =
oWord.InchesToPoints(1);


                }


Is there any way of doing this with XML? Here is a sample of my
(working) XML code:

string saveLocation =
System.Configuration.ConfigurationManager.AppSettings["DocFileLocation"].To­
String();


            string sURL = saveLocation + "QuotationTemplate.xml";//
template
            string sOutput = saveLocation + "Q-" +
thisJob.JobReferenceNo + ".xml"; // output


            string rptxml;
            StreamReader sr = new StreamReader(sURL);
            rptxml = sr.ReadToEnd();
            sr.Close();
            sr.Dispose();


            string strTag = "«USERNAME»";
            string sVal = thisUser.FirstName.ToString() + " " +
thisUser.LastName.ToString();
            rptxml = rptxml.Replace(strTag, sVal);


StreamWriter sw = new StreamWriter(sOutput);
            sw.Write(rptxml);
            sw.Close();
            sw.Dispose();


Reply via email to