PageRenderTime 27ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/XlLateBinding/Examples/Example10/Form1.cs

#
C# | 557 lines | 400 code | 127 blank | 30 comment | 7 complexity | 09eeaf6bf90a5662ec58fa4d0e0d7cf8 MD5 | raw file
  1. using System;
  2. using System.Xml;
  3. using System.Data;
  4. using System.Windows.Forms;
  5. using System.Reflection;
  6. using System.Globalization;
  7. using Excel = LateBindingApi.Excel;
  8. using LateBindingApi.Excel.Enums;
  9. namespace Example10
  10. {
  11. public partial class Form1 : Form
  12. {
  13. /// <summary>
  14. /// month and year to report, no selection dialog in this example
  15. /// the sample data contains datasets from 01/2008 - 06/2010
  16. /// </summary>
  17. private readonly int _yearToReport = 2009;
  18. private readonly int _monthToReport = 5;
  19. #region Fields
  20. Excel.Application _excelApplication;
  21. SalesReport _report;
  22. #endregion
  23. #region Construction
  24. public Form1()
  25. {
  26. InitializeComponent();
  27. }
  28. #endregion
  29. #region Gui Trigger
  30. private void button1_Click(object sender, EventArgs e)
  31. {
  32. // start excel and turn off msg boxes
  33. _excelApplication = new Excel.Application();
  34. _excelApplication.DisplayAlerts = false;
  35. _excelApplication.ScreenUpdating = false;
  36. // add a new workbook
  37. Excel.Workbook workBook = _excelApplication.Workbooks.Add();
  38. // we use the first sheet as summary sheet and remove the 2 last sheets
  39. Excel.Worksheet summarySheet = workBook.Worksheets[1];
  40. workBook.Worksheets[3].Delete();
  41. workBook.Worksheets[2].Delete();
  42. // we get the data & perform the report
  43. _report = new SalesReport(_yearToReport, _monthToReport);
  44. _report.Proceed();
  45. // we create named styles for the range.Style property
  46. CreateStorageAndRankingStyle(workBook, "StorageAndRanking");
  47. CreateMonthStyle(workBook, "MonthInfos");
  48. CreateMonthStyle(workBook, "YearTotalInfos");
  49. // write product sheets
  50. Excel.Worksheet productSheet = null;
  51. foreach (SalesReportProduct itemProduct in _report.Products)
  52. {
  53. productSheet = workBook.Worksheets.Add();
  54. ProceedProductWorksheet(productSheet, itemProduct);
  55. productSheet.Move(Missing.Value, workBook.Worksheets[workBook.Worksheets.Count]);
  56. }
  57. // write summary sheet
  58. ProceedSummaryWorksheet(_report, workBook,summarySheet, productSheet);
  59. summarySheet.get_Range("$A2").Select();
  60. // save the book
  61. string fileExtension = Helper.GetDefaultExtension(_excelApplication);
  62. string workbookFile = string.Format("{0}\\Example10{1}", Environment.CurrentDirectory, fileExtension);
  63. workBook.SaveAs(workbookFile);
  64. // close excel and dispose reference
  65. _excelApplication.Quit();
  66. _excelApplication.Dispose();
  67. FinishDialog fDialog = new FinishDialog("Workbook saved.", workbookFile);
  68. fDialog.ShowDialog(this);
  69. }
  70. #endregion
  71. #region Write Summary to Worksheet Functions
  72. private void ProceedSummaryMatrix(SalesReport report, Excel.Worksheet summarySheet, Excel.Style matrixStyle)
  73. {
  74. // table columns
  75. summarySheet.get_Range("B2").Value = "Count";
  76. summarySheet.get_Range("C2").Value = "Revenue";
  77. summarySheet.get_Range("D2").Value = "%";
  78. summarySheet.get_Range("E2").Value = "Storage";
  79. string leftBottomCellAdress = Helper.ToCellAdress(1, 3 + report.Products.Length);
  80. string rightBottomCellAdress = Helper.ToCellAdress(5, 3 + report.Products.Length);
  81. summarySheet.get_Range("$A2:$" + rightBottomCellAdress).Style = matrixStyle;
  82. int rowIndex = 3;
  83. int columnIndex = 1;
  84. int i = 0;
  85. foreach (SalesReportProduct itemProduct in report.Products)
  86. {
  87. string prodName = itemProduct.ProductName;
  88. int prodId = itemProduct.ProductId;
  89. summarySheet.Cells[rowIndex, columnIndex].Value = prodName;
  90. string formula = string.Format("='{0}-{1}'!{2}", itemProduct.ProductName, itemProduct.ProductId, Helper.ToCellAdress(_monthToReport + 1, 13));
  91. summarySheet.Cells[rowIndex, columnIndex + 1].Value = formula;
  92. formula = string.Format("='{0}-{1}'!{2}", itemProduct.ProductName, itemProduct.ProductId, Helper.ToCellAdress(_monthToReport + 1, 12));
  93. summarySheet.Cells[rowIndex, columnIndex + 2].Value = formula;
  94. formula = string.Format("={0}*100/{1}", Helper.ToCellAdress(3, rowIndex), Helper.ToCellAdress(3, 3 + report.Products.Length));
  95. summarySheet.Cells[rowIndex, columnIndex + 3].Formula = formula;
  96. formula = string.Format("='{0}-{1}'!{2}", itemProduct.ProductName, itemProduct.ProductId, "B6");
  97. summarySheet.Cells[rowIndex, columnIndex + 4].Value = formula;
  98. int storeCount = Convert.ToInt16(summarySheet.Cells[rowIndex, columnIndex + 4].Value);
  99. if( (i%2) == 0)
  100. summarySheet.get_Range("$A" + (i + 3).ToString() + ":$E" + (i + 3).ToString()).Interior.Color = Helper.ToDouble(System.Drawing.Color.Gainsboro);
  101. rowIndex++;
  102. i++;
  103. }
  104. string sumFormula = string.Format("=Sum({0}:{1})", "C3", "C" + (report.Products.Length + 3 - 1).ToString());
  105. summarySheet.Cells[rowIndex, columnIndex + 2].Value = sumFormula;
  106. summarySheet.get_Range("$C3:$C" + (report.Products.Length+3).ToString()).NumberFormat = "#,##0.00 €";
  107. summarySheet.get_Range("$D3:$D" + (report.Products.Length + 3).ToString()).NumberFormat = "0\"%\"";
  108. summarySheet.Cells[3 + report.Products.Length,1].Value = "Total:";
  109. summarySheet.get_Range("D2").HorizontalAlignment = XlHAlign.xlHAlignCenter;
  110. summarySheet.get_Range("$B2:$E2").Font.Bold = true;
  111. summarySheet.get_Range(leftBottomCellAdress + ":" + rightBottomCellAdress).Font.Bold = true;
  112. summarySheet.get_Range(leftBottomCellAdress + ":" + rightBottomCellAdress).BorderAround(XlLineStyle.xlDouble, XlBorderWeight.xlMedium);
  113. }
  114. private void ProceedSummaryWorksheet(SalesReport report, Excel.Workbook workBook, Excel.Worksheet summarySheet, Excel.Worksheet afterSheet)
  115. {
  116. summarySheet.Name = "Summary";
  117. Excel.Style matrixStyle = CreateSummaryStyle(workBook, "MatrixStyle");
  118. ProceedSummaryMatrix(report, summarySheet, matrixStyle);
  119. ProceedSummaryWorksheetCharts(summarySheet, report.Products.Length+1);
  120. ProceedSummaryPrintSettings(summarySheet);
  121. summarySheet.Columns.AutoFit();// proceed AutoFit before header
  122. ProceedSummaryWorksheetHeader(summarySheet);
  123. summarySheet.Select();
  124. }
  125. private void ProceedSummaryWorksheetCharts(Excel.Worksheet summarySheet, int countOfProducts)
  126. {
  127. string captionRangeAdress = "$A2:$" + Helper.ToCellAdress(1, 1 + countOfProducts);
  128. string fieldRangeAdress = "$C2:$" + Helper.ToCellAdress(3, 1 + countOfProducts);
  129. double chartTopPosition = summarySheet.Rows[countOfProducts+5].Top;
  130. double chartWidth = summarySheet.Columns[13].Left;
  131. Excel.ChartObject chartSummary = summarySheet.ChartObjects().Add(1, chartTopPosition, chartWidth, 260);
  132. chartSummary.Chart.SetSourceData(summarySheet.get_Range(captionRangeAdress + ";" + fieldRangeAdress));
  133. fieldRangeAdress = "$D2:$" + Helper.ToCellAdress(4, 1 + countOfProducts);
  134. chartTopPosition = summarySheet.Rows[2].Top;
  135. double chartLeftPosition = summarySheet.Columns[8].Left;
  136. double chartHeight = summarySheet.Rows[countOfProducts + 3].Top - chartTopPosition;
  137. chartWidth = summarySheet.Columns[13].Left - summarySheet.Columns[8].Left;
  138. Excel.ChartObject chartPercentOutcome = summarySheet.ChartObjects().Add(chartLeftPosition, chartTopPosition, chartWidth, chartHeight);
  139. chartPercentOutcome.Chart.ChartType = XlChartType.xlPie;
  140. chartPercentOutcome.Chart.SetSourceData(summarySheet.get_Range(captionRangeAdress + ";" + fieldRangeAdress));
  141. }
  142. private void ProceedSummaryWorksheetHeader(Excel.Worksheet summarySheet)
  143. {
  144. summarySheet.PageSetup.LeftHeader = "&D created";
  145. summarySheet.PageSetup.CenterHeader = "Vintage Digital Inc.";
  146. summarySheet.PageSetup.RightHeader = string.Format("Monthly Sales Report {1:00}/{0}", _yearToReport, _monthToReport);
  147. }
  148. private void ProceedSummaryPrintSettings(Excel.Worksheet summarySheet)
  149. {
  150. summarySheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
  151. summarySheet.PageSetup.Zoom = false;
  152. summarySheet.PageSetup.FitToPagesTall = 1;
  153. summarySheet.PageSetup.FitToPagesWide = 1;
  154. }
  155. private Excel.Style CreateSummaryStyle(Excel.Workbook workBook, string styleName)
  156. {
  157. /*
  158. * borders in styles doesnt realy working, very simple using is possible with the index trick. thats all
  159. */
  160. Excel.Style newStyle = workBook.Styles.Add(styleName);
  161. newStyle.Font.Size = 12;
  162. newStyle.Font.Name = "Courier New";
  163. newStyle.Borders[(XlBordersIndex)Constants.xlTop].LineStyle = XlLineStyle.xlContinuous;
  164. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Color = 0;
  165. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Weight = 2;
  166. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].LineStyle = XlLineStyle.xlContinuous;
  167. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Color = 0;
  168. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Weight = 2;
  169. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].LineStyle = XlLineStyle.xlDouble;
  170. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Color = 0;
  171. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Weight = 2;
  172. newStyle.Borders[(XlBordersIndex)Constants.xlRight].LineStyle = XlLineStyle.xlLineStyleNone;
  173. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Color = 0;
  174. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Weight = 2;
  175. return newStyle;
  176. }
  177. #endregion
  178. #region Write Product to Worksheet Functions
  179. private void ProceedProductWorksheet(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
  180. {
  181. string sheetName = string.Format("{0}-{1}", itemProduct.ProductName, itemProduct.ProductId.ToString());
  182. productSheet.Name = sheetName;
  183. // its not a random chain, write data first and create charts second
  184. ProceedProductStorageInfo(productSheet, itemProduct);
  185. ProceedProductMonthInfo(productSheet, itemProduct);
  186. ProceedProductYearTotalInfo(productSheet, itemProduct);
  187. ProceedProductMonthCharts(productSheet, itemProduct);
  188. ProceedProductPrintSettings(productSheet);
  189. productSheet.Columns.AutoFit(); // proceed AutoFit before header & ranking
  190. ProceedProductWorksheetHeader(productSheet, itemProduct);
  191. ProceedProductRankingInfo(productSheet, itemProduct);
  192. productSheet.Columns[14].ColumnWidth = 2.14;
  193. productSheet.Columns[17].ColumnWidth = 5.14;
  194. }
  195. private void ProceedProductStorageInfo(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
  196. {
  197. int rowIndex = 3;
  198. int columnIndex = 1;
  199. // we use the native invoker to set the style as string
  200. Excel.Range range = productSheet.get_Range("$A3:$B6");
  201. LateBindingApi.Core.Invoker.PropertySet(range, "Style", "StorageAndRanking");
  202. productSheet.Cells[rowIndex, columnIndex].Value = "Storage Info";
  203. productSheet.Cells[rowIndex, columnIndex].Font.Bold = true;
  204. productSheet.Cells[rowIndex + 1, columnIndex].Value = "Storage Count";
  205. productSheet.Cells[rowIndex + 2, columnIndex].Value = "Sales in Progress";
  206. productSheet.Cells[rowIndex + 3, columnIndex].Value = "Recalc Storage Count ";
  207. productSheet.Cells[rowIndex + 1, columnIndex + 1].Value = itemProduct.StorageCount;
  208. productSheet.Cells[rowIndex + 2, columnIndex + 1].Value = itemProduct.OpenOrders.CountOfSales;
  209. productSheet.Cells[rowIndex + 3, columnIndex + 1].Value = itemProduct.StorageCount - itemProduct.OpenOrders.CountOfSales;
  210. SetProductStorageCountColor(itemProduct.StorageCount, productSheet.Cells[rowIndex + 1, columnIndex + 1]);
  211. SetProductStorageCountColor(itemProduct.StorageCount - itemProduct.OpenOrders.CountOfSales, productSheet.Cells[rowIndex + 3, columnIndex + 1]);
  212. }
  213. private void ProceedProductRankingInfo(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
  214. {
  215. int rowIndex = 3;
  216. int columnIndex = 4;
  217. // we use the native invoker to set the style as string
  218. Excel.Range range = productSheet.get_Range("$D3:$F6");
  219. LateBindingApi.Core.Invoker.PropertySet(range, "Style", "StorageAndRanking");
  220. productSheet.Cells[rowIndex, columnIndex].Value = "Count Ranking";
  221. productSheet.Cells[rowIndex, columnIndex].Font.Bold = true;
  222. productSheet.Cells[rowIndex + 1, columnIndex].Value = "Month";
  223. productSheet.Cells[rowIndex + 2, columnIndex].Value = "Year";
  224. productSheet.Cells[rowIndex + 3, columnIndex].Value = "Total";
  225. productSheet.Cells[rowIndex + 1, columnIndex + 2].Value = itemProduct.SalesRankMonth;
  226. productSheet.Cells[rowIndex + 2, columnIndex + 2].Value = itemProduct.SalesRankYear;
  227. productSheet.Cells[rowIndex + 3, columnIndex + 2].Value = itemProduct.SalesRankTotal;
  228. productSheet.get_Range("$D4:$E6").Borders[XlBordersIndex.xlInsideVertical].LineStyle = XlLineStyle.xlLineStyleNone;
  229. }
  230. private void ProceedProductMonthInfo(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
  231. {
  232. int rowIndex = 9;
  233. int iMonthCellIndex = 1;
  234. // we use the native invoker to set the style as string
  235. Excel.Range range = productSheet.get_Range("$A9:$M13");
  236. LateBindingApi.Core.Invoker.PropertySet(range, "Style", "MonthInfos");
  237. productSheet.Cells[rowIndex + 1, iMonthCellIndex].Value = "ManufacturerPriceSummary";
  238. productSheet.Cells[rowIndex + 2, iMonthCellIndex].Value = "SalesPricesSummary";
  239. productSheet.Cells[rowIndex + 3, iMonthCellIndex].Value = "TotalRevenue";
  240. productSheet.Cells[rowIndex + 4, iMonthCellIndex].Value = "CountOfSales";
  241. iMonthCellIndex = 2; ;
  242. foreach (SalesReportReportEntity itemMonth in itemProduct.PrevMonths)
  243. {
  244. productSheet.Cells[rowIndex, iMonthCellIndex].Value = GetMonthName(iMonthCellIndex - 2);
  245. productSheet.Cells[rowIndex + 1, iMonthCellIndex].Value = itemMonth.ManufactorPriceSummary;
  246. productSheet.Cells[rowIndex + 2, iMonthCellIndex].Value = itemMonth.SalesPricesSummary;
  247. productSheet.Cells[rowIndex + 3, iMonthCellIndex].Value = itemMonth.OutcomeSummary;
  248. productSheet.Cells[rowIndex + 4, iMonthCellIndex].Value = itemMonth.CountOfSales;
  249. iMonthCellIndex++;
  250. }
  251. string cellAdress1 = Helper.ToCellAdress(itemProduct.PrevMonths.Count + 2, 10);
  252. string cellAdress2 = Helper.ToCellAdress(itemProduct.PrevMonths.Count + 2, 12);
  253. productSheet.get_Range("$B10:$" + cellAdress1).Interior.Color = Helper.ToDouble(System.Drawing.Color.Gainsboro);
  254. productSheet.get_Range("$B12:$" + cellAdress2).Interior.Color = Helper.ToDouble(System.Drawing.Color.Gainsboro);
  255. productSheet.Cells[rowIndex, iMonthCellIndex].Value = GetMonthName(_monthToReport - 1);
  256. productSheet.Cells[rowIndex + 1, iMonthCellIndex].Value = itemProduct.Month.ManufactorPriceSummary;
  257. productSheet.Cells[rowIndex + 2, iMonthCellIndex].Value = itemProduct.Month.SalesPricesSummary;
  258. productSheet.Cells[rowIndex + 3, iMonthCellIndex].Value = itemProduct.Month.OutcomeSummary;
  259. productSheet.Cells[rowIndex + 4, iMonthCellIndex].Value = itemProduct.Month.CountOfSales;
  260. for (int i = itemProduct.PrevMonths.Count + 2; i <= 12; i++)
  261. {
  262. iMonthCellIndex++;
  263. productSheet.Cells[rowIndex, iMonthCellIndex].Value = GetMonthName(i - 1);
  264. }
  265. productSheet.get_Range("$B9:$M9").NumberFormat = "";
  266. productSheet.get_Range("$B9:$M9").Font.Bold = true;
  267. productSheet.get_Range("$B13:$M13").NumberFormat = "";
  268. productSheet.get_Range("$B13:$M13").HorizontalAlignment = XlHAlign.xlHAlignCenter;
  269. if (itemProduct.PrevMonths.Count < 11)
  270. {
  271. string topLeftMergeCellAdress = "$" + Helper.ToCellAdress(itemProduct.PrevMonths.Count + 3, 10);
  272. productSheet.get_Range(topLeftMergeCellAdress + ":$M13").MergeCells = true;
  273. }
  274. }
  275. private void ProceedProductPrintSettings(Excel.Worksheet productSheet)
  276. {
  277. productSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
  278. productSheet.PageSetup.Zoom = false;
  279. productSheet.PageSetup.FitToPagesTall = 1;
  280. productSheet.PageSetup.FitToPagesWide = 1;
  281. productSheet.PageSetup.PrintArea = "$A$1:$R$39";
  282. }
  283. private void ProceedProductMonthCharts(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
  284. {
  285. double chartTop = productSheet.Rows[15].Top;
  286. double chartWidth = productSheet.Columns[14].Left;
  287. double chartHeight = productSheet.Rows[30].Top -productSheet.Rows[15].Top;
  288. Excel.ChartObject chartMonths = productSheet.ChartObjects().Add(1, chartTop, chartWidth, chartHeight);
  289. chartMonths.Chart.SetSourceData(productSheet.get_Range("$A9:$M12"));
  290. chartTop = productSheet.Rows[31].Top;
  291. chartWidth = productSheet.Columns[14].Left;
  292. chartHeight = productSheet.Rows[40].Top - productSheet.Rows[33].Top;
  293. Excel.ChartObject chartCountMonths = productSheet.ChartObjects().Add(1, chartTop, chartWidth, chartHeight);
  294. chartCountMonths.Chart.ChartType = XlChartType.xlLine;
  295. chartCountMonths.Chart.SetSourceData(productSheet.get_Range("$A13:$M13"));
  296. double chartLeft = productSheet.Columns[15].Left;
  297. chartTop = productSheet.Rows[15].Top;
  298. chartWidth = productSheet.Columns[19].Left - productSheet.Columns[15].Left;
  299. chartHeight = productSheet.Rows[30].Top - productSheet.Rows[15].Top;
  300. Excel.ChartObject chartCountYears = productSheet.ChartObjects().Add(chartLeft, chartTop, chartWidth, chartHeight);
  301. chartCountYears.Chart.ChartType = XlChartType.xlCylinderColClustered;
  302. chartCountYears.Chart.SetSourceData(productSheet.get_Range("$O9:$P12"));
  303. }
  304. private void ProceedProductWorksheetHeader(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
  305. {
  306. int rowIndex = 1;
  307. int columnIndex = 1;
  308. productSheet.PageSetup.LeftHeader = "&D created";
  309. productSheet.PageSetup.CenterHeader = "Vintage Digital Inc.";
  310. productSheet.PageSetup.RightHeader = string.Format("Monthly Sales Report {1:00}/{0}", _yearToReport, _monthToReport);
  311. productSheet.Cells[rowIndex, columnIndex].Value = itemProduct.ProductName;
  312. productSheet.Cells[rowIndex, columnIndex].Font.Bold = true;
  313. productSheet.Cells[rowIndex, columnIndex].Font.Underline = true;
  314. productSheet.Cells[rowIndex, columnIndex].Font.Size = 14;
  315. productSheet.Cells[rowIndex, columnIndex].Font.Name = "Verdana";
  316. }
  317. private void ProceedProductYearTotalInfo(Excel.Worksheet productSheet, SalesReportProduct itemProduct)
  318. {
  319. int ColumnIndex = 15;
  320. int RowIndex = 9;
  321. LateBindingApi.Core.Invoker.PropertySet(productSheet.get_Range("$O9:$R13"), "Style", "YearTotalInfos");
  322. productSheet.Cells[RowIndex, ColumnIndex].Value = "Year " + _yearToReport.ToString();
  323. productSheet.Cells[RowIndex + 1, ColumnIndex].Value = itemProduct.Year.ManufactorPriceSummary;
  324. productSheet.Cells[RowIndex + 2, ColumnIndex].Value = itemProduct.Year.SalesPricesSummary;
  325. productSheet.Cells[RowIndex + 3, ColumnIndex].Value = itemProduct.Year.OutcomeSummary;
  326. productSheet.Cells[RowIndex + 4, ColumnIndex].Value = itemProduct.Year.CountOfSales;
  327. productSheet.Cells[RowIndex, ColumnIndex + 1].Value = "Year " + (_yearToReport - 1).ToString();
  328. productSheet.Cells[RowIndex + 1, ColumnIndex + 1].Value = itemProduct.PrevYear.ManufactorPriceSummary;
  329. productSheet.Cells[RowIndex + 2, ColumnIndex + 1].Value = itemProduct.PrevYear.SalesPricesSummary;
  330. productSheet.Cells[RowIndex + 3, ColumnIndex + 1].Value = itemProduct.PrevYear.OutcomeSummary;
  331. productSheet.Cells[RowIndex + 4, ColumnIndex + 1].Value = itemProduct.PrevYear.CountOfSales;
  332. productSheet.get_Range("$O10:$P10").Interior.Color = Helper.ToDouble(System.Drawing.Color.Gainsboro);
  333. productSheet.get_Range("$O12:$P12").Interior.Color = Helper.ToDouble(System.Drawing.Color.Gainsboro);
  334. ColumnIndex = 18;
  335. RowIndex = 9;
  336. productSheet.Cells[RowIndex, ColumnIndex].Value = "Total";
  337. productSheet.Cells[RowIndex + 1, ColumnIndex].Value = itemProduct.Total.ManufactorPriceSummary;
  338. productSheet.Cells[RowIndex + 2, ColumnIndex].Value = itemProduct.Total.SalesPricesSummary;
  339. productSheet.Cells[RowIndex + 3, ColumnIndex].Value = itemProduct.Total.OutcomeSummary;
  340. productSheet.Cells[RowIndex + 4, ColumnIndex].Value = itemProduct.Total.CountOfSales;
  341. productSheet.get_Range("$R10").Interior.Color = Helper.ToDouble(System.Drawing.Color.Gainsboro);
  342. productSheet.get_Range("$R12").Interior.Color = Helper.ToDouble(System.Drawing.Color.Gainsboro);
  343. productSheet.get_Range("$O9:$R9").NumberFormat = "";
  344. productSheet.get_Range("$O9:$R9").Font.Bold = true;
  345. productSheet.get_Range("$O13:$R13").NumberFormat = "";
  346. productSheet.get_Range("$O13:$R13").HorizontalAlignment = XlHAlign.xlHAlignCenter;
  347. productSheet.get_Range("$Q9:$Q13").MergeCells = true;
  348. }
  349. private Excel.Style CreateStorageAndRankingStyle(Excel.Workbook workBook, string styleName)
  350. {
  351. /*
  352. * borders in styles doesnt realy working, very simple using is possible with the index trick. thats all
  353. */
  354. Excel.Style newStyle = workBook.Styles.Add(styleName);
  355. newStyle.Font.Size = 12;
  356. newStyle.Font.Name = "Courier New";
  357. newStyle.Borders[(XlBordersIndex)Constants.xlTop].LineStyle = XlLineStyle.xlContinuous;
  358. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Color = 0;
  359. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Weight = 2;
  360. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlContinuous;
  361. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Color = 0;
  362. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Weight = 2;
  363. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlDouble;
  364. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Color = 0;
  365. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Weight = 2;
  366. newStyle.Borders[(XlBordersIndex)Constants.xlRight].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlLineStyleNone;
  367. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Color = 0;
  368. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Weight = 2;
  369. return newStyle;
  370. }
  371. private Excel.Style CreateMonthStyle(Excel.Workbook workBook, string styleName)
  372. {
  373. /*
  374. * borders in styles doesnt realy working, very simple using is possible with the index trick. thats all
  375. */
  376. Excel.Style newStyle = workBook.Styles.Add(styleName);
  377. newStyle.Font.Size = 12;
  378. newStyle.Borders[(XlBordersIndex)Constants.xlTop].LineStyle = XlLineStyle.xlContinuous;
  379. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Color = 0;
  380. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Weight = 2;
  381. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlContinuous;
  382. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Color = 0;
  383. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Weight = 2;
  384. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlDouble;
  385. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Color = 0;
  386. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Weight = 2;
  387. newStyle.Borders[(XlBordersIndex)Constants.xlRight].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlLineStyleNone;
  388. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Color = 0;
  389. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Weight = 2;
  390. newStyle.NumberFormat = "#,##0.00 €";
  391. return newStyle;
  392. }
  393. private Excel.Style CreateYearTotalStyle(Excel.Workbook workBook, string styleName)
  394. {
  395. /*
  396. * borders in styles doesnt realy working, very simple using is possible with the index trick. thats all
  397. */
  398. Excel.Style newStyle = workBook.Styles.Add(styleName);
  399. newStyle.Font.Size = 12;
  400. newStyle.Borders[(XlBordersIndex)Constants.xlTop].LineStyle = XlLineStyle.xlContinuous;
  401. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Color = 0;
  402. newStyle.Borders[(XlBordersIndex)Constants.xlTop].Weight = 2;
  403. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlContinuous;
  404. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Color = 0;
  405. newStyle.Borders[(XlBordersIndex)Constants.xlBottom].Weight = 2;
  406. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlDouble;
  407. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Color = 0;
  408. newStyle.Borders[(XlBordersIndex)Constants.xlLeft].Weight = 2;
  409. newStyle.Borders[(XlBordersIndex)Constants.xlRight].LineStyle = LateBindingApi.Excel.Enums.XlLineStyle.xlLineStyleNone;
  410. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Color = 0;
  411. newStyle.Borders[(XlBordersIndex)Constants.xlRight].Weight = 2;
  412. newStyle.NumberFormat = "#,##0.00 €";
  413. return newStyle;
  414. }
  415. private string GetMonthName(int index)
  416. {
  417. return LateBindingApi.Core.Settings.ThreadCulture.DateTimeFormat.MonthNames[index].Substring(0, 3);
  418. }
  419. private void SetProductStorageCountColor(int storageCount, Excel.Range range)
  420. {
  421. if (storageCount <= 50)
  422. range.Interior.Color = Helper.ToDouble(System.Drawing.Color.Red);
  423. else if (storageCount <= 100)
  424. range.Interior.Color = Helper.ToDouble(System.Drawing.Color.Yellow);
  425. else
  426. range.Interior.Color = Helper.ToDouble(System.Drawing.Color.Green);
  427. }
  428. #endregion
  429. }
  430. }