コード例 #1
0
ファイル: Program.cs プロジェクト: JohanLindvall/PicoXLSX
        /// <summary>
        /// This demo shows the usage of hiding rows and columns, auto-filter and worksheet name sanitizing
        /// </summary>
        private static void Demo7()
        {
            Workbook workbook           = new Workbook(false);                                          // Create new workbook without worksheet
            String   invalidSheetName   = "Sheet?1";                                                    // ? is not allowed in the names of worksheets
            String   sanitizedSheetName = Worksheet.SanitizeWorksheetName(invalidSheetName, workbook);  // Method to sanitize a worksheet name (replaces ? with _)

            workbook.AddWorksheet(sanitizedSheetName);                                                  // Add new worksheet
            Worksheet     ws     = workbook.CurrentWorksheet;                                           // Create reference (shortening)
            List <object> values = new List <object>()
            {
                "Cell A1", "Cell B1", "Cell C1", "Cell D1"
            };                                                                                          // Create a List of values

            ws.AddCellRange(values, "A1:D1");                                                           // Insert cell range
            values = new List <object>()
            {
                "Cell A2", "Cell B2", "Cell C2", "Cell D2"
            };                                                                                          // Create a List of values
            ws.AddCellRange(values, "A2:D2");                                                           // Insert cell range
            values = new List <object>()
            {
                "Cell A3", "Cell B3", "Cell C3", "Cell D3"
            };                                                                                          // Create a List of values
            ws.AddCellRange(values, "A3:D3");                                                           // Insert cell range
            ws.AddHiddenColumn("C");                                                                    // Hide column C
            ws.AddHiddenRow(1);                                                                         // Hider row 2 (zero-based: 1)
            ws.SetAutoFilter(1, 3);                                                                     // Set auto-filter for column B to D
            workbook.SaveAs("test7.xlsx");                                                              // Save the workbook
        }