コード例 #1
0
        ///<summary>
        /// Creates a single-or-multi-sheet spreadsheet from a List of Discrepancies.
        ///</summary>
        public static void CreateDiscrepancySheets(this IWorkbook workbook, List <Discrepancy> discreps)
        {
            var discCount  = discreps.Count; // Tracking our total number of discreps
            var discIndex  = 0;              // Tracking our current index across groups
            var sheetIndex = 1;              // Tracking our current sheet number

            for (var groupCount = (decimal)discreps.Count / 3; groupCount > 0; groupCount--)
            {
                // Create a sheet
                var sheet = workbook.CreateSheet($"DiscrepanciesPage{sheetIndex}");
                sheet.SetupForDiscrepancy();
                sheetIndex++;

                // Create the styles and font dictionaries to pass to extension methods
                var styleDict = workbook.CreateCellStyleDict();
                var fontDict  = workbook.CreateFonts();

                // Write a header, always using our first discrepancy for the information
                sheet.WriteHeader(styleDict, fontDict, discreps[0]);
                sheet.WriteBufferRow(1);

                var startingIndex = 2; // How we will track our starting index

                // In each group, we write up to a maximum of 3 discrepancies.
                for (int i = 0; i < 2; i++)
                {
                    // If our current index is below or at the last index in the list
                    if (discIndex <= discCount - 1)
                    {
                        sheet.WriteDiscrepancy(styleDict, fontDict, startingIndex, discreps[discIndex]);
                        sheet.WriteBufferRow(startingIndex + 10);

                        discIndex++; // Update our index
                    }
                    // TODO: add an empty discrepancy object somewhere to fill out blank fields
                    else
                    {
                    }
                    startingIndex += 11; // Add 11 to the starting index for the next discrepancy
                }
            }
        }