CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    2

    print out function problem()

    i m using below code..by using it i able to write asp data into word file n format it.but i m facing problen in print out..

    please hav a look to below code....

    view plaincopy to clipboardprint?
    .................div data...................
    <div id="printdiv" runat="server">
    <table style="border: 5px solid #FF00FF; width:100%">
    <tr>
    <th align="left" style="background-color: #00FFFF">Vikas:Ji</th>
    </tr>
    <tr>
    <th align="right" style="background-color: #800000">Vikas:Ji</th>
    </tr>
    <tr>
    <th>Vikas:</th>
    </tr>
    <tr>
    <th>Vikas:</th>
    </tr>
    <tr>
    <td></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    </table>
    </div>


    ..............to write dive data into word file
    public void PrintControl()
    {
    try
    {
    String strr = printdiv.InnerHtml;


    string strPath = "C:\\Documents and Settings\\hgtech\\Desktop\\WordForm\\abc.doc";


    FileStream fStream = File.Create(strPath);
    fStream.Close();
    StreamWriter sWriter = new StreamWriter(strPath);
    sWriter.Write(strr);
    sWriter.Close();
    edit_changes();


    }
    catch (Exception err)
    {
    //error.Text = err.Message;
    }
    }

    .........................To format the word file...set left and top margin.........................

    private void edit_changes()
    {

    Object missing = System.Reflection.Missing.Value;
    Object fileName = "C:\\Documents and Settings\\hgtech\\Desktop\\WordForm\\abc.doc";
    Word.Application wordApp = new Word.ApplicationClass();
    Word.Document oDoc = new Word.Document(); ;
    Object;
    // oDoc.Close(ref missing, ref missing, ref missing);
    if (File.Exists((String)fileName))
    {
    DateTime today = DateTime.Now;

    Object isVisible = false;
    wordApp.Visible = false;
    oDoc = wordApp.Documents.Open(ref fileName, ref missing, ref
    missing, ref missing, ref missing, ref missing, ref
    missing, ref missing, ref missing, ref missing, ref
    isVisible, ref missing, ref missing, ref missing, ref missing);
    oDoc.Activate();
    oDoc.PageSetup.TopMargin = 150.0f;
    oDoc.PageSetup.BottomMargin = 200.0f;


    }


    object Background = true;
    object Range = Word.WdPrintOutRange.wdPrintAllDocument;
    object Copies = 2;
    object PageType = Word.WdPrintOutPages.wdPrintAllPages;
    object PrintToFile = false;
    object Collate = false;
    object ActivePrinterMacGX = missing;
    object ManualDuplexPrint = false;
    object PrintZoomColumn = 1;
    object PrintZoomRow = 1;

    oDoc.Close(ref missing, ref missing, ref missing);
    oDoc.PrintOut(ref Background, ref missing, ref Range, ref missing,
    ref missing, ref missing, ref missing, ref Copies,
    ref missing, ref PageType, ref PrintToFile, ref Collate,
    ref missing, ref ManualDuplexPrint, ref PrintZoomColumn,
    ref PrintZoomRow, ref missing, ref missing);

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: print out function problem()

    That's nice. Just put all your code here and expect everyone to magically fix all your errors. Sorry, it doesn't work like that. Tell us exactly where your problem is and what it is what you're trying to do. Please also use &#091;CODE] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: print out function problem()

    You need to supply values to the parameters:
    Code:
    oDoc.Close(ref missing, ref missing, ref missing);
    oDoc.PrintOut(ref Background, ref missing, ref Range, ref missing,
    ref missing, ref missing, ref missing, ref Copies,
    ref missing, ref PageType, ref PrintToFile, ref Collate,
    ref missing, ref ManualDuplexPrint, ref PrintZoomColumn,
    ref PrintZoomRow, ref missing, ref missing);
    Reply With Quote
    What is this? "ref missing"
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured