3.5.2 commit
This commit is contained in:
577
BDF.cs
577
BDF.cs
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Spire.Xls;
|
||||
|
||||
namespace bdf
|
||||
{
|
||||
@@ -9,8 +8,8 @@ namespace bdf
|
||||
{
|
||||
public Int32 Row_Number { get; set; } = 1;
|
||||
public Int32 Record_Type { get; set; } = 2;
|
||||
public Int32 Contractor_Billing_Account_Number { get; set; } = 857412;
|
||||
public Int32 Invoice_Number { get; set; } = 61262091;
|
||||
public Int32 Contractor_Billing_Account_Number { get; set; } = 0; // This will change for each service type
|
||||
public String Invoice_Number { get; set; } = "INV X";
|
||||
public Int32 Invoice_Period { get; set; } = 0;
|
||||
public String Canada_Contract_Identifier { get; set; } = "X";
|
||||
public String Contractor { get; set; } = "ROGERS";
|
||||
@@ -36,7 +35,7 @@ namespace bdf
|
||||
public Double Total_GST_Amount { get; set; } = 0;
|
||||
//public Double Total_PST_Amount { get; set; } = 0;
|
||||
public Double Total_HST_Amount { get; set; } = 0;
|
||||
public Double Total_QST_Amount { get; set; } = 0;
|
||||
public Double Total_QST_Amount { get; set; } = 0; // to be used for both PST and QST per call with Diana Aboud Feb 9, 2026
|
||||
public Double Total_Taxes { get; set; } = 0;
|
||||
public Double Total_Amount_including_taxes { get; set; } = 0;
|
||||
public String CI_Name { get; set; } = "X";
|
||||
@@ -44,6 +43,12 @@ namespace bdf
|
||||
public String TCID { get; set; } = "X";
|
||||
public String PO_Number { get; set; } = "";
|
||||
public String TA_Number { get; set; } = "X";
|
||||
|
||||
//var copy = original.Clone<MyClass>();
|
||||
public T Clone<T>() where T : class
|
||||
{
|
||||
return (T)this.MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
||||
public class Row2 // Generic Type 1
|
||||
@@ -81,62 +86,19 @@ namespace bdf
|
||||
public String Department { get; set; } = "X";
|
||||
public String SCID { get; set; } = "X";
|
||||
public Int32 Total_Usage_Charges_for_the_Month { get; set; } = 0;
|
||||
public Int32 Total_Other_Charges_and_Credits { get; set; } = 0;
|
||||
public Int32 Total_GST_Amount { get; set; } = 0;
|
||||
//public Int32 Total_PST_Amount { get; set; } = 0;
|
||||
public Int32 Total_HST_Amount { get; set; } = 0;
|
||||
public Int32 Total_QST_Amount { get; set; } = 0;
|
||||
public Int32 Total_Taxes { get; set; } = 0;
|
||||
public Int32 Total_Amount_Including_Taxes { get; set; } = 0;
|
||||
public String PO_Number { get; set; } = "X";
|
||||
}
|
||||
|
||||
public class BDF
|
||||
{
|
||||
public static Row CopyRow(Row r)
|
||||
{
|
||||
Row n = new Row { };
|
||||
|
||||
n.Row_Number = r.Row_Number;
|
||||
n.Record_Type = r.Record_Type;
|
||||
n.Contractor_Billing_Account_Number = r.Contractor_Billing_Account_Number;
|
||||
n.Invoice_Number = r.Invoice_Number;
|
||||
n.Invoice_Period = r.Invoice_Period;
|
||||
n.Canada_Contract_Identifier = r.Canada_Contract_Identifier;
|
||||
n.Contractor = r.Contractor;
|
||||
n.SSC_Order_Number = r.SSC_Order_Number;
|
||||
n.SSC_Version = r.SSC_Version;
|
||||
n.SSC_Seq_No = r.SSC_Seq_No;
|
||||
n.SDPID = r.SDPID;
|
||||
n.Department = r.Department;
|
||||
n.Prov = r.Prov;
|
||||
n.Service_Project_ID = r.Service_Project_ID;
|
||||
n.Billing_Effective_Date = r.Billing_Effective_Date;
|
||||
n.Billing_End_Date = r.Billing_End_Date;
|
||||
n.Billing_Cancel_Date = r.Billing_Cancel_Date;
|
||||
n.Period_of_Service = r.Period_of_Service;
|
||||
n.SCID = r.SCID;
|
||||
n.Quantity = r.Quantity;
|
||||
n.Recurring_Charges_for_the_Month = r.Recurring_Charges_for_the_Month;
|
||||
n.Total_Recurring_Charges_for_the_Month = n.Total_Recurring_Charges_for_the_Month;
|
||||
n.Non_recurring_Charges_for_the_Month = r.Non_recurring_Charges_for_the_Month;
|
||||
n.Total_Non_recurring_Charges_for_the_Month = r.Total_Non_recurring_Charges_for_the_Month;
|
||||
n.Total_Service_Credits = r.Total_Service_Credits;
|
||||
n.Total_Other_Charges_and_Credits = r.Total_Other_Charges_and_Credits;
|
||||
n.Total_GST_Amount = r.Total_GST_Amount;
|
||||
n.Total_HST_Amount = r.Total_HST_Amount;
|
||||
//n.Total_PST_Amount = r.Total_PST_Amount; // do not uncomment creates a extra ghost column in output
|
||||
n.Total_QST_Amount = r.Total_QST_Amount;
|
||||
n.Total_Taxes = r.Total_Taxes;
|
||||
n.Total_Amount_including_taxes = r.Total_Amount_including_taxes;
|
||||
n.CI_Name = r.CI_Name;
|
||||
n.CI_Name_2 = r.CI_Name_2;
|
||||
n.TCID = r.TCID;
|
||||
n.PO_Number = r.PO_Number;
|
||||
n.TA_Number = r.TA_Number;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public static Spire.Xls.Workbook S_CreateBDF(string type)
|
||||
public static Spire.Xls.Workbook CreateBDF(string type)
|
||||
{
|
||||
if (type == "LDF" || type == "WAV")
|
||||
return S_CreateBDF();
|
||||
@@ -153,7 +115,6 @@ namespace bdf
|
||||
cleanSheets(ref workbook);
|
||||
|
||||
{
|
||||
|
||||
//Headers "SIP BDF Type 1"
|
||||
|
||||
worksheet1.Range[1, 1].Value = "Record Type";
|
||||
@@ -174,7 +135,6 @@ namespace bdf
|
||||
worksheet1.Range[1, 16].Value = "Total Amount Including Taxes";
|
||||
worksheet1.Range[1, 17].Value = "Total Usage Charges"; // this line was the only delta
|
||||
|
||||
|
||||
var worksheet2 = workbook.Worksheets.Add("BDF Type 2");
|
||||
//Headers "BDF Type 2"
|
||||
|
||||
@@ -229,22 +189,22 @@ namespace bdf
|
||||
worksheet3.Range[1, 9].Value = "Department";
|
||||
worksheet3.Range[1, 10].Value = "SCID";
|
||||
worksheet3.Range[1, 11].Value = "Total Usage Charges for the Month";
|
||||
worksheet3.Range[1, 12].Value = "Total GST Amount";
|
||||
worksheet3.Range[1, 13].Value = "Total HST Amount";
|
||||
worksheet3.Range[1, 14].Value = "Total QST Amount";
|
||||
worksheet3.Range[1, 15].Value = "Total Taxes";
|
||||
worksheet3.Range[1, 16].Value = "Total Amount including taxes";
|
||||
worksheet3.Range[1, 12].Value = "Total Other Charges and Credits";
|
||||
worksheet3.Range[1, 13].Value = "Total GST Amount";
|
||||
worksheet3.Range[1, 14].Value = "Total HST Amount";
|
||||
worksheet3.Range[1, 15].Value = "Total QST Amount";
|
||||
worksheet3.Range[1, 16].Value = "Total Taxes";
|
||||
worksheet3.Range[1, 17].Value = "Total Amount including taxes";
|
||||
worksheet3.Range[1, 18].Value = "PO Number";
|
||||
}
|
||||
|
||||
Logger.Log(0, "Excel BDF template file created! {0}", bdf.dirpath + bdf.filename);
|
||||
Logger.Log(0, "Excel BDF template file created! {0}", bdf.output_path + bdf.filename);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static Spire.Xls.Workbook S_CreateBDF()
|
||||
{
|
||||
var workbook = new Spire.Xls.Workbook();
|
||||
//using (var workbook = new XLWorkbook())
|
||||
//Console.WriteLine("WS Count = {0}", workbook.Worksheets.Count);
|
||||
var worksheet1 = workbook.Worksheets.Add("BDF Type 1");
|
||||
cleanSheets(ref workbook);
|
||||
|
||||
@@ -255,7 +215,7 @@ namespace bdf
|
||||
worksheet1.Range[1, 2].Value = "Invoice Date";
|
||||
worksheet1.Range[1, 3].Value = "Invoice Period";
|
||||
worksheet1.Range[1, 4].Value = "Canada Contract Identifier";
|
||||
worksheet1.Range[1, 5].Value = "Contractor";
|
||||
worksheet1.Range[1, 5].Value = "Contractor Name";
|
||||
worksheet1.Range[1, 6].Value = "Total Recurring Charges for the Month";
|
||||
worksheet1.Range[1, 7].Value = "Total Non-Recurring Charges for the Month";
|
||||
worksheet1.Range[1, 8].Value = "Total Charges Excluding Taxes";
|
||||
@@ -311,7 +271,7 @@ namespace bdf
|
||||
|
||||
}
|
||||
|
||||
Logger.Log(0, "Excel BDF template file created! {0}", bdf.dirpath + bdf.filename);
|
||||
Logger.Log(0, "Excel BDF template file created! {0}", bdf.output_path + bdf.filename);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
@@ -403,7 +363,7 @@ namespace bdf
|
||||
// ------------------------------------------------------
|
||||
|
||||
Spire.Xls.CellRange tableRange = worksheet.Range[startRow, startCol, totalRows, totalCols];
|
||||
TableFormatter.ApplyTableFormat(tableRange);
|
||||
ApplyTableFormat(tableRange);
|
||||
|
||||
// ------------------------------------------
|
||||
// Autofit column widths to contents
|
||||
@@ -412,79 +372,77 @@ namespace bdf
|
||||
|
||||
}
|
||||
|
||||
public static class TableFormatter
|
||||
/*
|
||||
/// Applies "table-style" formatting to a specified range:
|
||||
/// - Bold gray header row
|
||||
/// - Bordered cells
|
||||
/// - Alternating (banded) row background colors
|
||||
/// Fully compatible with FreeSpire.XLS.
|
||||
/// </summary>
|
||||
/// <param name="range">Spire.Xls.CellRange to format</param>
|
||||
///
|
||||
// Spire.Xls.Worksheet sheet = wb.Worksheets[0];
|
||||
|
||||
// Define a range with header + rows
|
||||
// Spire.Xls.CellRange tableRange = sheet.Range["A1:D10"];
|
||||
|
||||
// Apply table styling
|
||||
// TableFormatter.ApplyTableFormat(tableRange);
|
||||
*/
|
||||
|
||||
public static void ApplyTableFormat(Spire.Xls.CellRange range)
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies "table-style" formatting to a specified range:
|
||||
/// - Bold gray header row
|
||||
/// - Bordered cells
|
||||
/// - Alternating (banded) row background colors
|
||||
/// Fully compatible with FreeSpire.XLS.
|
||||
/// </summary>
|
||||
/// <param name="range">Spire.Xls.CellRange to format</param>
|
||||
///
|
||||
// Spire.Xls.Worksheet sheet = wb.Worksheets[0];
|
||||
if (range == null)
|
||||
throw new System.ArgumentNullException("range");
|
||||
|
||||
// Define a range with header + rows
|
||||
// Spire.Xls.CellRange tableRange = sheet.Range["A1:D10"];
|
||||
int rowCount = range.RowCount;
|
||||
int colCount = range.ColumnCount;
|
||||
|
||||
// Apply table styling
|
||||
// TableFormatter.ApplyTableFormat(tableRange);
|
||||
if (rowCount == 0 || colCount == 0)
|
||||
return;
|
||||
|
||||
public static void ApplyTableFormat(Spire.Xls.CellRange range)
|
||||
// ---------------------------
|
||||
// 1. Format Header Row
|
||||
// ---------------------------
|
||||
for (int col = 0; col < colCount; col++)
|
||||
{
|
||||
if (range == null)
|
||||
throw new System.ArgumentNullException("range");
|
||||
Spire.Xls.CellRange headerCell =
|
||||
range[1, col + 1]; // 1-based indexing inside CellRange segment
|
||||
|
||||
int rowCount = range.RowCount;
|
||||
int colCount = range.ColumnCount;
|
||||
headerCell.Style.Font.IsBold = true;
|
||||
headerCell.Style.Color = System.Drawing.Color.LightGray;
|
||||
headerCell.Style.Borders.LineStyle = Spire.Xls.LineStyleType.Thin;
|
||||
|
||||
if (rowCount == 0 || colCount == 0)
|
||||
return;
|
||||
|
||||
// ---------------------------
|
||||
// 1. Format Header Row
|
||||
// ---------------------------
|
||||
for (int col = 0; col < colCount; col++)
|
||||
{
|
||||
Spire.Xls.CellRange headerCell =
|
||||
range[1, col + 1]; // 1-based indexing inside CellRange segment
|
||||
|
||||
headerCell.Style.Font.IsBold = true;
|
||||
headerCell.Style.Color = System.Drawing.Color.LightGray;
|
||||
headerCell.Style.Borders.LineStyle = Spire.Xls.LineStyleType.Thin;
|
||||
|
||||
headerCell.Borders[Spire.Xls.BordersLineType.DiagonalDown].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
headerCell.Borders[Spire.Xls.BordersLineType.DiagonalUp].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
// 2. Format Data Rows (banded)
|
||||
// ---------------------------
|
||||
for (int row = 2; row <= rowCount; row++)
|
||||
{
|
||||
bool isEven = (row % 2 == 0);
|
||||
System.Drawing.Color rowColor = isEven
|
||||
? System.Drawing.Color.FromArgb(245, 245, 245) // light gray band
|
||||
: System.Drawing.Color.White;
|
||||
|
||||
for (int col = 1; col <= colCount; col++)
|
||||
{
|
||||
Spire.Xls.CellRange cell = range[row, col];
|
||||
|
||||
cell.Style.Color = rowColor;
|
||||
cell.Style.Borders.LineStyle = Spire.Xls.LineStyleType.Thin;
|
||||
|
||||
cell.Borders[Spire.Xls.BordersLineType.DiagonalDown].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
cell.Borders[Spire.Xls.BordersLineType.DiagonalUp].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
// 3. Auto-fit column widths
|
||||
// ---------------------------
|
||||
range.AutoFitColumns();
|
||||
headerCell.Borders[Spire.Xls.BordersLineType.DiagonalDown].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
headerCell.Borders[Spire.Xls.BordersLineType.DiagonalUp].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
// 2. Format Data Rows (banded)
|
||||
// ---------------------------
|
||||
for (int row = 2; row <= rowCount; row++)
|
||||
{
|
||||
bool isEven = (row % 2 == 0);
|
||||
System.Drawing.Color rowColor = isEven
|
||||
? System.Drawing.Color.FromArgb(245, 245, 245) // light gray band
|
||||
: System.Drawing.Color.White;
|
||||
|
||||
for (int col = 1; col <= colCount; col++)
|
||||
{
|
||||
Spire.Xls.CellRange cell = range[row, col];
|
||||
|
||||
cell.Style.Color = rowColor;
|
||||
cell.Style.Borders.LineStyle = Spire.Xls.LineStyleType.Thin;
|
||||
|
||||
cell.Borders[Spire.Xls.BordersLineType.DiagonalDown].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
cell.Borders[Spire.Xls.BordersLineType.DiagonalUp].LineStyle = Spire.Xls.LineStyleType.None;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
// 3. Auto-fit column widths
|
||||
// ---------------------------
|
||||
range.AutoFitColumns();
|
||||
}
|
||||
|
||||
public static void cleanSheets(ref Spire.Xls.Workbook workbook)
|
||||
@@ -496,366 +454,5 @@ namespace bdf
|
||||
workbook.Worksheets.RemoveAt(0);
|
||||
}
|
||||
|
||||
/*
|
||||
public static XLWorkbook CreateBDF(string type)
|
||||
{
|
||||
if (type == "LDF" || type == "WAV")
|
||||
return CreateBDF();
|
||||
else if (type == "SIP")
|
||||
return CreateBDFSIP();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static XLWorkbook CreateBDF()
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
//using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet1 = workbook.Worksheets.Add("BDF Type 1");
|
||||
//Headers "BDF Type 1"
|
||||
|
||||
worksheet1.Cell(1, 1).Value = "Record Type";
|
||||
worksheet1.Cell(1, 2).Value = "Invoice Date";
|
||||
worksheet1.Cell(1, 3).Value = "Invoice Period";
|
||||
worksheet1.Cell(1, 4).Value = "Canada Contract Identifier";
|
||||
worksheet1.Cell(1, 5).Value = "Contractor Name";
|
||||
worksheet1.Cell(1, 6).Value = "Total Recurring Charges for the Month";
|
||||
worksheet1.Cell(1, 7).Value = "Total Non-Recurring Charges for the Month";
|
||||
worksheet1.Cell(1, 8).Value = "Total Charges Excluding Taxes";
|
||||
worksheet1.Cell(1, 9).Value = "Total Other Charges and Credits";
|
||||
worksheet1.Cell(1, 10).Value = "Total Service Credits";
|
||||
worksheet1.Cell(1, 11).Value = "Total Late Payment Amount";
|
||||
worksheet1.Cell(1, 12).Value = "Total GST Amount";
|
||||
worksheet1.Cell(1, 13).Value = "Total HST Amount";
|
||||
worksheet1.Cell(1, 14).Value = "Total QST Amount";
|
||||
worksheet1.Cell(1, 15).Value = "Total Taxes";
|
||||
worksheet1.Cell(1, 16).Value = "Total Amount Including Taxes";
|
||||
|
||||
|
||||
var worksheet2 = workbook.Worksheets.Add("BDF Type 2");
|
||||
//Headers "BDF Type 2"
|
||||
|
||||
worksheet2.Cell(1, 1).Value = "Row Number";
|
||||
worksheet2.Cell(1, 2).Value = "Record Type";
|
||||
worksheet2.Cell(1, 3).Value = "Contractor Billing Account Number";
|
||||
worksheet2.Cell(1, 4).Value = "Invoice Number";
|
||||
worksheet2.Cell(1, 5).Value = "Invoice Period";
|
||||
worksheet2.Cell(1, 6).Value = "Canada Contract Identifier";
|
||||
worksheet2.Cell(1, 7).Value = "Contractor";
|
||||
worksheet2.Cell(1, 8).Value = "SSC Order Number";
|
||||
worksheet2.Cell(1, 9).Value = "SSC Version";
|
||||
worksheet2.Cell(1, 10).Value = "SSC Seq No";
|
||||
worksheet2.Cell(1, 11).Value = "SDPID";
|
||||
worksheet2.Cell(1, 12).Value = "Department";
|
||||
worksheet2.Cell(1, 13).Value = "Prov";
|
||||
worksheet2.Cell(1, 14).Value = "Service Project ID";
|
||||
worksheet2.Cell(1, 15).Value = "Billing Effective Date";
|
||||
worksheet2.Cell(1, 16).Value = "Billing End Date";
|
||||
worksheet2.Cell(1, 17).Value = "Billing Cancel Date";
|
||||
worksheet2.Cell(1, 18).Value = "Period of Service";
|
||||
worksheet2.Cell(1, 19).Value = "SCID";
|
||||
worksheet2.Cell(1, 20).Value = "Quantity";
|
||||
worksheet2.Cell(1, 21).Value = "Recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 22).Value = "Total Recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 23).Value = "Non-recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 24).Value = "Total Non-recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 25).Value = "Total Service Credits";
|
||||
worksheet2.Cell(1, 26).Value = "Total Other Charges and Credits";
|
||||
worksheet2.Cell(1, 27).Value = "Total GST Amount";
|
||||
worksheet2.Cell(1, 28).Value = "Total HST Amount";
|
||||
worksheet2.Cell(1, 29).Value = "Total QST Amount";
|
||||
worksheet2.Cell(1, 30).Value = "Total Taxes";
|
||||
worksheet2.Cell(1, 31).Value = "Total Amount including taxes";
|
||||
worksheet2.Cell(1, 32).Value = "CI Name";
|
||||
worksheet2.Cell(1, 33).Value = "CI Name 2";
|
||||
worksheet2.Cell(1, 34).Value = "TCID";
|
||||
worksheet2.Cell(1, 35).Value = "PO Number";
|
||||
worksheet2.Cell(1, 36).Value = "TA Number";
|
||||
|
||||
}
|
||||
|
||||
Logger.Log(0, "Excel BDF template file created! {0}", bdf.dirpath + bdf.filename);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static XLWorkbook CreateBDFSIP()
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
//using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet1 = workbook.Worksheets.Add("BDF Type 1");
|
||||
//Headers "SIP BDF Type 1"
|
||||
|
||||
worksheet1.Cell(1, 1).Value = "Record Type";
|
||||
worksheet1.Cell(1, 2).Value = "Invoice Date";
|
||||
worksheet1.Cell(1, 3).Value = "Invoice Period";
|
||||
worksheet1.Cell(1, 4).Value = "Canada Contract Identifier";
|
||||
worksheet1.Cell(1, 5).Value = "Contractor";
|
||||
worksheet1.Cell(1, 6).Value = "Total Recurring Charges for the Month";
|
||||
worksheet1.Cell(1, 7).Value = "Total Non-Recurring Charges for the Month";
|
||||
worksheet1.Cell(1, 8).Value = "Total Charges Excluding Taxes";
|
||||
worksheet1.Cell(1, 9).Value = "Total Other Charges and Credits";
|
||||
worksheet1.Cell(1, 10).Value = "Total Service Credits";
|
||||
worksheet1.Cell(1, 11).Value = "Total Late Payment Amount";
|
||||
worksheet1.Cell(1, 12).Value = "Total GST Amount";
|
||||
worksheet1.Cell(1, 13).Value = "Total HST Amount";
|
||||
worksheet1.Cell(1, 14).Value = "Total QST Amount";
|
||||
worksheet1.Cell(1, 15).Value = "Total Taxes";
|
||||
worksheet1.Cell(1, 16).Value = "Total Amount Including Taxes";
|
||||
worksheet1.Cell(1, 17).Value = "Total Usage Charges"; // this line was the only delta
|
||||
|
||||
|
||||
var worksheet2 = workbook.Worksheets.Add("BDF Type 2");
|
||||
//Headers "BDF Type 2"
|
||||
|
||||
worksheet2.Cell(1, 1).Value = "Line Number"; //slight change
|
||||
worksheet2.Cell(1, 2).Value = "Record Type";
|
||||
worksheet2.Cell(1, 3).Value = "Contractor Billing Account Number";
|
||||
worksheet2.Cell(1, 4).Value = "Invoice Number";
|
||||
worksheet2.Cell(1, 5).Value = "Invoice Period";
|
||||
worksheet2.Cell(1, 6).Value = "Canada Contract Identifier";
|
||||
worksheet2.Cell(1, 7).Value = "Contractor";
|
||||
worksheet2.Cell(1, 8).Value = "SSC Reference Number"; //slight change
|
||||
worksheet2.Cell(1, 9).Value = "SSC Version";
|
||||
worksheet2.Cell(1, 10).Value = "SSC Seq No";
|
||||
worksheet2.Cell(1, 11).Value = "SDPID";
|
||||
worksheet2.Cell(1, 12).Value = "Department";
|
||||
worksheet2.Cell(1, 13).Value = "Prov";
|
||||
worksheet2.Cell(1, 14).Value = "Service Project ID";
|
||||
worksheet2.Cell(1, 15).Value = "Billing Effective Date";
|
||||
worksheet2.Cell(1, 16).Value = "Billing End Date";
|
||||
worksheet2.Cell(1, 17).Value = "Billing Cancel Date";
|
||||
worksheet2.Cell(1, 18).Value = "Period of Service";
|
||||
worksheet2.Cell(1, 19).Value = "SCID";
|
||||
worksheet2.Cell(1, 20).Value = "Qty"; //slight change
|
||||
worksheet2.Cell(1, 21).Value = "Recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 22).Value = "Total Recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 23).Value = "Non-recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 24).Value = "Total Non-recurring Charges for the Month";
|
||||
worksheet2.Cell(1, 25).Value = "Total Service Credits";
|
||||
worksheet2.Cell(1, 26).Value = "Total Other Charges and Credits";
|
||||
worksheet2.Cell(1, 27).Value = "Total GST Amount";
|
||||
worksheet2.Cell(1, 28).Value = "Total HST Amount";
|
||||
worksheet2.Cell(1, 29).Value = "Total QST Amount";
|
||||
worksheet2.Cell(1, 30).Value = "Total Taxes";
|
||||
worksheet2.Cell(1, 31).Value = "Total Amount including taxes";
|
||||
worksheet2.Cell(1, 32).Value = "CI Name";
|
||||
worksheet2.Cell(1, 33).Value = "CI Name 2";
|
||||
worksheet2.Cell(1, 34).Value = "TCID";
|
||||
worksheet2.Cell(1, 35).Value = "PO #"; //slight change
|
||||
// worksheet2.Cell(1, 36).Value = "TA Number"; //this line removed for SIP-2
|
||||
|
||||
var worksheet3 = workbook.Worksheets.Add("BDF Type 3");
|
||||
//Headers "SIP BDF Type 3"
|
||||
|
||||
worksheet3.Cell(1, 1).Value = "Line Number";
|
||||
worksheet3.Cell(1, 2).Value = "Record Type";
|
||||
worksheet3.Cell(1, 3).Value = "Contractor Billing Account Number";
|
||||
worksheet3.Cell(1, 4).Value = "Invoice Number";
|
||||
worksheet3.Cell(1, 5).Value = "Invoice Period";
|
||||
worksheet3.Cell(1, 6).Value = "Canada Contract Identifier";
|
||||
worksheet3.Cell(1, 7).Value = "Contractor";
|
||||
worksheet3.Cell(1, 8).Value = "Period of Service";
|
||||
worksheet3.Cell(1, 9).Value = "Department";
|
||||
worksheet3.Cell(1, 10).Value = "SCID";
|
||||
worksheet3.Cell(1, 11).Value = "Total Usage Charges for the Month";
|
||||
worksheet3.Cell(1, 12).Value = "Total GST Amount";
|
||||
worksheet3.Cell(1, 13).Value = "Total HST Amount";
|
||||
worksheet3.Cell(1, 14).Value = "Total QST Amount";
|
||||
worksheet3.Cell(1, 15).Value = "Total Taxes";
|
||||
worksheet3.Cell(1, 16).Value = "Total Amount including taxes";
|
||||
}
|
||||
|
||||
Logger.Log(0, "Excel BDF template file created! {0}", bdf.dirpath + bdf.filename);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static void InsertData<T>(IXLWorksheet worksheet, List<T> items)
|
||||
{
|
||||
if (items == null || items.Count == 0)
|
||||
return;
|
||||
|
||||
var type = typeof(T);
|
||||
var props = type.GetProperties();
|
||||
|
||||
//Logger.Log(0, "prop={0} items={1}", props.Length, items.Count);
|
||||
|
||||
// Write headers
|
||||
//for (int i = 0; i < props.Length; i++)
|
||||
//{
|
||||
// //Logger.Log(0, "name={0}", props[i].Name);
|
||||
// worksheet.Cell(1, i + 1).Value = props[i].Name;
|
||||
// worksheet.Cell(1, i + 1).Style.Font.Bold = true;
|
||||
//}
|
||||
|
||||
|
||||
// Write data
|
||||
for (int r = 0; r < items.Count; r++)
|
||||
{
|
||||
for (int c = 0; c < props.Length; c++)
|
||||
{
|
||||
//if (props[c].Name == "Total_PST_Amount") continue;
|
||||
|
||||
|
||||
//Logger.Log(0, "value={0}", props[c].GetValue(items[r], null));
|
||||
var value = props[c].GetValue(items[r], null);
|
||||
|
||||
//Console.WriteLine("props {0}:{1}", props[c].Name, value);
|
||||
if (props[c].Name.ToString() == "Billing_Cancel_Date") // GOC wants this field bank instead of 0
|
||||
{
|
||||
//Console.WriteLine("skip");
|
||||
continue;
|
||||
}
|
||||
|
||||
//Logger.Log(0, "Type={0}", value.GetType().Name);
|
||||
try
|
||||
{
|
||||
|
||||
if (value.GetType().Name == "Int32")
|
||||
{
|
||||
worksheet.Cell(r + 2, c + 1).Value = (Int32)value;
|
||||
}
|
||||
else if (value.GetType().Name == "String")
|
||||
{
|
||||
worksheet.Cell(r + 2, c + 1).Value = (String)value;
|
||||
}
|
||||
else if (value.GetType().Name == "Double")
|
||||
{
|
||||
worksheet.Cell(r + 2, c + 1).Value = (Double)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
worksheet.Cell(r + 2, c + 1).Value = "z";
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log(0, "Exception: {0} : {1} !", e.Message, e.InnerException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Format table
|
||||
//Logger.Log("Making range");
|
||||
var range = worksheet.Range(1, 1, items.Count + 1, props.Length);
|
||||
//Logger.Log("Making table");
|
||||
range.CreateTable();
|
||||
worksheet.Columns().AdjustToContents();
|
||||
}
|
||||
|
||||
|
||||
public class ListObject
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public Spire.Xls.Worksheet Sheet { get; private set; }
|
||||
public CellRange Range { get; private set; }
|
||||
|
||||
public ListObject(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a fake ListObject-style table at the given worksheet and row/column.
|
||||
/// </summary>
|
||||
public void CreateTable<T>(Spire.Xls.Worksheet sheet, int startRow, int startCol, List<T> items)
|
||||
{
|
||||
Sheet = sheet;
|
||||
|
||||
if (items == null || items.Count == 0)
|
||||
throw new ArgumentException("Items list must contain at least one element.");
|
||||
|
||||
PropertyInfo[] props = typeof(T)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
int row = startRow;
|
||||
int col = startCol;
|
||||
|
||||
// ---------------------------------------------------
|
||||
// HEADER ROW
|
||||
// ---------------------------------------------------
|
||||
for (int i = 0; i < props.Length; i++)
|
||||
{
|
||||
CellRange cell = sheet.Range[row, col + i];
|
||||
cell.Text = props[i].Name;
|
||||
|
||||
cell.Style.Font.IsBold = true;
|
||||
cell.Style.Color = System.Drawing.Color.LightGray;
|
||||
cell.Style.Borders.LineStyle = LineStyleType.Thin;
|
||||
}
|
||||
|
||||
row++;
|
||||
|
||||
// ---------------------------------------------------
|
||||
// DATA ROWS
|
||||
// ---------------------------------------------------
|
||||
int dataStartRow = row;
|
||||
int itemIndex = 0;
|
||||
|
||||
foreach (T item in items)
|
||||
{
|
||||
for (int i = 0; i < props.Length; i++)
|
||||
{
|
||||
object value = props[i].GetValue(item, null);
|
||||
CellRange cell = sheet.Range[row, col + i];
|
||||
cell.Value2 = value;
|
||||
|
||||
// Border
|
||||
cell.Style.Borders.LineStyle = LineStyleType.Thin;
|
||||
|
||||
// Alternating (banded) rows
|
||||
if (itemIndex % 2 == 0)
|
||||
cell.Style.Color = System.Drawing.Color.White;
|
||||
else
|
||||
cell.Style.Color = System.Drawing.Color.FromArgb(245, 245, 245);
|
||||
}
|
||||
|
||||
itemIndex++;
|
||||
row++;
|
||||
}
|
||||
|
||||
int lastRow = row - 1;
|
||||
int lastCol = col + props.Length - 1;
|
||||
|
||||
// Record the table's occupied range
|
||||
Range = sheet.Range[startRow, startCol, lastRow, lastCol];
|
||||
|
||||
// ---------------------------------------------------
|
||||
// AUTO-FIT WIDTHS
|
||||
// ---------------------------------------------------
|
||||
Range.AutoFitColumns();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates all values in an existing fake ListObject.
|
||||
/// </summary>
|
||||
public void Refresh<T>(List<T> items)
|
||||
{
|
||||
if (Sheet == null || Range == null)
|
||||
throw new InvalidOperationException("Table has not been created.");
|
||||
|
||||
PropertyInfo[] props = typeof(T)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
int headerRow = Range.Row;
|
||||
int dataStartRow = headerRow + 1;
|
||||
|
||||
int row = dataStartRow;
|
||||
int col = Range.Column;
|
||||
|
||||
foreach (T item in items)
|
||||
{
|
||||
for (int i = 0; i < props.Length; i++)
|
||||
{
|
||||
object value = props[i].GetValue(item, null);
|
||||
Sheet.Range[row, col + i].Value2 = value;
|
||||
}
|
||||
row++;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user