CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Location
    Lahore, Pakistan.
    Posts
    10

    Bill Printing in C#

    Hi,
    I am working on a billing system. Everything was fine until I got a problem while printing the bills.
    I have to do something like this:

    Code:
    for(int i=0; i<noOfHouse; i++)
    {
          -> read bill template (excel file that contains text and images)
          -> change the bill amounts for ith house reading from DB
          -> and then print the bill
    }
    Currently I am doing it like:
    reading excel bill-template file and copying it cell-by-cell into another excel file except the cells that need to be changed.

    Once the bill files are generated from the above for-loop, I've planned that the operator would select all the files and print them manually.


    Can anyone give a better idea ??

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Bill Printing in C#

    I would think you could automate the printing easy enough but if it were me I would not be using Excel. SQL Server or the like with the needed reports would in most if not all cases be a MUCH better choice.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Oct 2009
    Location
    Lahore, Pakistan.
    Posts
    10

    Re: Bill Printing in C#

    I did it like this:

    Code:
    xlApp = new Excel.ApplicationClass();
                    xlWorkBook = xlApp.Workbooks.Open(@"D:\Askari9\" + billTemplateFileName, Type.Missing, true, Type.Missing, "permitAskari9", "permitAskari9", Type.Missing, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                    range = (Excel.Range)xlWorkSheet.UsedRange;
    
    
    for (int i = 0; i < lstHouseNo.Count; i++)
                {
                    (range.Cells[12, 3] as Excel.Range).Value2 = lstOwnerName.ElementAt<String>(i); // Owner Name
                    (range.Cells[13, 3] as Excel.Range).Value2 = lstHouseNo.ElementAt<String>(i); // House Number
                    (range.Cells[14, 3] as Excel.Range).Value2 = textBoxBillingMonth.Text; // Billing Month
                    (range.Cells[15, 3] as Excel.Range).Value2 = textBoxDueDate.Text; // Due Date
                    (range.Cells[18, 6] as Excel.Range).Value2 = textBoxServiceCharges.Text; // Service Charges
                    (range.Cells[21, 6] as Excel.Range).Value2 = lstArrears.ElementAt<String>(i); // Arreaes
                    (range.Cells[24, 6] as Excel.Range).Value2 = lstMisc.ElementAt<String>(i); // Misc
    
    
                    ((Excel._Workbook)xlWorkBook).PrintOut(missing, missing,
                        missing, missing, missing,
                        missing, missing, missing);
    
                    // Time taken by printer to process one document -- keeps printer's job queue in control
                    Thread.Sleep(1000);
    
                    //SetLabelPropertyValue.Text = "Status: Printing bill for: " + Reader.GetValue(houseNoFieldIndexInDB).ToString().Trim();
                    SetStatusLableValue(toolStripStatusLabel1, "Text", "Status: Printing bill for: " + lstHouseNo.ElementAt<String>(i));
    
                    //printingProgressBar.Value = printingProgressBar.Value + 1;
                    SetControlPropertyValue(printingProgressBar, "Value", printingProgressBar.Value + 1);
    
                }
    
    
    
    
                xlWorkBook.Save();
                xlWorkBook.Close(false, null, null); // parameter#1 is false as i dont want to save changes to my template file
                xlApp.Quit();
    
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);


    And this is exactly what I wanted

Tags for this Thread

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