Bill Printing in C#
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:
Currently I am doing it like:
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
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 ??
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.
Re: Bill Printing in C#
I did it like this:
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
missing, missing, missing,
missing, missing, missing);
// Time taken by printer to process one document -- keeps printer's job queue in control
//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.Close(false, null, null); // parameter#1 is false as i dont want to save changes to my template file
And this is exactly what I wanted :)