OK. I nearly have this working - so far so good.

I have ditched the XSLT and am using the XML version.

Here is some of the code:

string saveLocation =
System.Configuration.ConfigurationManager.AppSettings["DocFileLocation"].ToString();

            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();

Now, another bit that worked well with word was writing a few lines in
Table format, starting from a Bookmark:

// write table of items
                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 to replicate this using this XML method?

Stapes

On 27 Oct, 10:52, Jamie Fraser <[email protected]> wrote:
> Your file is actually XML, not XSLT.
>
> You simply need to load the XML in and replace the elements as necessary.
>
>
>
> On Wed, Oct 27, 2010 at 10:50 AM, stapes <[email protected]> wrote:
> > Hi
>
> > My application was writing into a Word Template. It worked
> > (sporadically) but there are a whole host of reasons why I shouldn't
> > use it.
> > Instead - research has suggested I use XSLT instead. Trouble is - I
> > cannot get a clear idea of how to.
> > I converted my Word Template (.dot) to XML (using Save As). Then
> > renamed it to .xslt.
> > At first I thought it had produecd rubbish. The resulting file looked
> > at gobbledegook. However on closer examination, all my data was in a
> > couple single long lines. Took hours to edit it up into some kind of
> > meanigfull format - indented etc.
>
> > Now I want to read this data in, search for the MERGEFIELDS, and
> > replace the placeholders with my data.
>
> > using System.Xml.Xsl;
> > XslCompiledTransform xslt = new XslCompiledTransform();
>
> >        string sURL = "C:/Inetpub/wwwroot/RTS/Docs/JobSheet1.xlst";
> >        xslt.Load(sURL);
>
> > So far so good.
>
> > This is an example of a piece of the xslt file showing one of the
> > placeholders:
>
> > <w:fldSimple w:instr=" MERGEFIELD  SITEADDRESS  \* MERGEFORMAT ">
> > <w:r>
> > <w:rPr>
> > <w:noProof/>
> > <w:sz w:val="20"/>
> > <w:sz-cs w:val="20"/>
> > </w:rPr>
> > <w:t>«SITEADDRESS»</w:t>
> > </w:r>
> > </w:fldSimple>
>
> > How do I get at this.- Hide quoted text -
>
> - Show quoted text -

Reply via email to