Thread: Print a File via Excel

  1. #1
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001

    Print a File via Excel

    Out of the ordinary (well a bit anyways)

    My program outputs an html file which is dynamically created.

    On the Print menu item, I'd like to open+print that file using excel, then have excel close right away.

    So far I haven't found anything to do with printing besides:

    using Excel;

    ...Well, there's my "discussion starter"

  2. #2
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Richmond, VA
    I believe I heard that there are ways you can tie into the Office suite via a .NET application. Once you get in, I'm sure there is a print method you can invoke.

    If you find a way to reference the Office suite, please let us know.

  3. #3
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001

    The Closest I've Found and it doesn't even Build ..

    using System;
    using System.Reflection; 
    using System.Runtime.InteropServices; 
    using Excel;
    class Excel {
     public static int Main() {
      Application exc = new Application();
      if (exc == null) {
       Console.WriteLine("ERROR: EXCEL couldn't be started!");
       return 0;
      exc.set_Visible(0, true); 
      Workbooks workbooks = exc.Workbooks;
      _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet, 0); 
      Sheets sheets = workbook.Worksheets;
      _Worksheet worksheet = (_Worksheet) sheets.get_Item(1);
      if (worksheet == null) {
       Console.WriteLine ("ERROR: worksheet == null");
      Range range1 = worksheet.get_Range("C1", Missing.Value);
      if (range1 == null) {
       Console.WriteLine ("ERROR: range == null");
      const int nCells = 1;
      Object[] args1 = new Object[1];
      args1[0] = nCells;
    range1.GetType().InvokeMember("Value", BindingFlags.SetProperty, null,range1, args1);
      return 100;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM