當前位置: 首頁>>代碼示例>>C#>>正文


C# XSSFWorkbook.GetProperties方法代碼示例

本文整理匯總了C#中NPOI.XSSF.UserModel.XSSFWorkbook.GetProperties方法的典型用法代碼示例。如果您正苦於以下問題:C# XSSFWorkbook.GetProperties方法的具體用法?C# XSSFWorkbook.GetProperties怎麽用?C# XSSFWorkbook.GetProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NPOI.XSSF.UserModel.XSSFWorkbook的用法示例。


在下文中一共展示了XSSFWorkbook.GetProperties方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestCustomProperties

        public void TestCustomProperties()
        {
            POIXMLDocument wb = new XSSFWorkbook();

            CustomProperties customProps = wb.GetProperties().CustomProperties;
            customProps.AddProperty("test-1", "string val");
            customProps.AddProperty("test-2", 1974);
            customProps.AddProperty("test-3", 36.6);
            //Adding a duplicate
            try
            {
                customProps.AddProperty("test-3", 36.6);
                Assert.Fail("expected exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual("A property with this name already exists in the custom properties", e.Message);
            }
            customProps.AddProperty("test-4", true);

            wb = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack((XSSFWorkbook)wb);
            CT_CustomProperties ctProps =
                    wb.GetProperties().CustomProperties.GetUnderlyingProperties();
            Assert.AreEqual(6, ctProps.sizeOfPropertyArray());
            CT_Property p;

            p = ctProps.GetPropertyArray(0);
            Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid);
            Assert.AreEqual("test-1", p.name);
            Assert.AreEqual("string val", p.Item.ToString());
            Assert.AreEqual(2, p.pid);

            p = ctProps.GetPropertyArray(1);
            Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid);
            Assert.AreEqual("test-2", p.name);
            Assert.AreEqual(1974, p.Item);
            Assert.AreEqual(3, p.pid);

            p = ctProps.GetPropertyArray(2);
            Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid);
            Assert.AreEqual("test-3", p.name);
            Assert.AreEqual(36.6, p.Item);
            Assert.AreEqual(4, p.pid);

            p = ctProps.GetPropertyArray(3);
            Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid);
            Assert.AreEqual("test-4", p.name);
            Assert.AreEqual(true, p.Item);
            Assert.AreEqual(5, p.pid);

            p = ctProps.GetPropertyArray(4);
            Assert.AreEqual("Generator", p.name);
            Assert.AreEqual("NPOI", p.Item);
            Assert.AreEqual(6, p.pid);

            //p = ctProps.GetPropertyArray(5);
            //Assert.AreEqual("Generator Version", p.name);
            //Assert.AreEqual("2.0.9", p.Item);
            //Assert.AreEqual(7, p.pid);
        }
開發者ID:JnS-Software-LLC,項目名稱:npoi,代碼行數:60,代碼來源:TestPOIXMLProperties.cs

示例2: Main

        static void Main(string[] args)
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            ISheet sheet1 = workbook.CreateSheet("Sheet1");

            POIXMLProperties props = workbook.GetProperties();
            props.GetCoreProperties().SetCreator("NPOI 2.0.5");
            props.GetCoreProperties().SetCreated(DateTime.Now);
            props.GetCustomProperties().AddProperty("NPOI Team", "Hello World!");

            FileStream sw = File.Create("test.xlsx");
            workbook.Write(sw);
            sw.Close();
        }
開發者ID:kahinke,項目名稱:npoi,代碼行數:14,代碼來源:Program.cs

示例3: TestWorkbookExtendedProperties

        public void TestWorkbookExtendedProperties()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            POIXMLProperties props = workbook.GetProperties();
            Assert.IsNotNull(props);

            ExtendedProperties properties =
                    props.ExtendedProperties;

            CT_ExtendedProperties
                    ctProps = properties.GetUnderlyingProperties();


            String appVersion = "3.5 beta";
            String application = "POI";

            ctProps.Application = (application);
            ctProps.AppVersion = (appVersion);

            ctProps = null;
            properties = null;
            props = null;

            XSSFWorkbook newWorkbook =
                    (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack(workbook);

            Assert.IsTrue(workbook != newWorkbook);


            POIXMLProperties newProps = newWorkbook.GetProperties();
            Assert.IsNotNull(newProps);
            ExtendedProperties newProperties =
                    newProps.ExtendedProperties;

            Assert.AreEqual(application, newProperties.Application);
            Assert.AreEqual(appVersion, newProperties.AppVersion);
        

            CT_ExtendedProperties
                    newCtProps = newProperties.GetUnderlyingProperties();

            Assert.AreEqual(application, newCtProps.Application);
            Assert.AreEqual(appVersion, newCtProps.AppVersion);


        }
開發者ID:Reinakumiko,項目名稱:npoi,代碼行數:46,代碼來源:TestPOIXMLProperties.cs

示例4: TestListOfCustomProperties

        public void TestListOfCustomProperties()
        {
            FileInfo inp = POIDataSamples.GetSpreadSheetInstance().GetFileInfo("ExcelWithAttachments.xlsm");
            OPCPackage pkg = OPCPackage.Open(inp, PackageAccess.READ);
            XSSFWorkbook wb = new XSSFWorkbook(pkg);

            Assert.IsNotNull(wb.GetProperties());
            Assert.IsNotNull(wb.GetProperties().CustomProperties);

            foreach (CT_Property prop in wb.GetProperties().CustomProperties.GetUnderlyingProperties().GetPropertyList())
            {
                Assert.IsNotNull(prop);
            }

            wb.Close();
            pkg.Close();
        }
開發者ID:Reinakumiko,項目名稱:npoi,代碼行數:17,代碼來源:TestPackageCoreProperties.cs

示例5: TestWorkbookProperties

        public void TestWorkbookProperties()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            POIXMLProperties props = workbook.GetProperties();
            Assert.IsNotNull(props);
            //the Application property must be set for new workbooks, see Bugzilla #47559
            Assert.AreEqual("NPOI", props.GetExtendedProperties().GetUnderlyingProperties().Application);

            PackagePropertiesPart opcProps = props.GetCoreProperties().GetUnderlyingProperties();
            Assert.IsNotNull(opcProps);

            opcProps.SetTitleProperty("Testing Bugzilla #47460");
            Assert.AreEqual("NPOI", opcProps.GetCreatorProperty());
            opcProps.SetCreatorProperty("[email protected]");

            workbook = (XSSFWorkbook) XSSFTestDataSamples.WriteOutAndReadBack(workbook);
            Assert.AreEqual("NPOI", workbook.GetProperties().GetExtendedProperties().GetUnderlyingProperties().Application);
            opcProps = workbook.GetProperties().GetCoreProperties().GetUnderlyingProperties();
            Assert.AreEqual("Testing Bugzilla #47460", opcProps.GetTitleProperty());
            Assert.AreEqual("[email protected]", opcProps.GetCreatorProperty());
        }
開發者ID:kahinke,項目名稱:npoi,代碼行數:21,代碼來源:TestXSSFWorkbook.cs

示例6: CreatWorkBook

        private string CreatWorkBook(string title)
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            //Create Excel的屬性中的來源以及說明等
            NPOI.POIXMLProperties props = workbook.GetProperties();
            props.CoreProperties.Creator = "王楊楊";
            props.CoreProperties.Created = DateTime.Now;
            props.CoreProperties.Title = title;
            props.CoreProperties.SetCreated(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
            props.CoreProperties.Subject = "文案激勵報單";
            //   props.CoreProperties.Description = "discription";
            props.CoreProperties.Category = "金吉列文件";

            ISheet sheet = workbook.CreateSheet("寄出個數");
            //編輯單元格
            //統一設置列寬
            sheet.SetColumnWidth(0, (int)((17.38 + 0.6) * 256));
            sheet.SetColumnWidth(1, (int)((13.5 + 0.6) * 256));
            sheet.SetColumnWidth(2, (int)((9.63 + 0.6) * 256));
            sheet.SetColumnWidth(3, (int)((9.63 + 0.6) * 256));
            sheet.SetColumnWidth(4, (int)((9.63 + 0.6) * 256));
            sheet.SetColumnWidth(5, (int)((9.63 + 0.6) * 256));
            sheet.SetColumnWidth(6, (int)((25.88 + 0.6) * 256));
            sheet.SetColumnWidth(7, (int)((11.5 + 0.6) * 256));
            sheet.SetColumnWidth(8, (int)((8 + 0.6) * 256));
            sheet.SetColumnWidth(9, (int)((7.75 + 0.6) * 256));
            sheet.SetColumnWidth(10, (int)((36.38 + 0.6) * 256));
            ICellStyle cellStyle = workbook.CreateCellStyle();
            IFont font = workbook.CreateFont();
            font.FontName = "宋體";
            font.Boldweight = short.MaxValue;
            // font.FontHeight = 20 * 20;
            font.FontHeightInPoints = 12;
            cellStyle.SetFont(font);
            cellStyle.Alignment = HorizontalAlignment.Center;
            //設置全局格式
            for (int i = 0; i < 10; i++)
            {
                sheet.SetDefaultColumnStyle(i, cellStyle);
            }

            IRow row = sheet.CreateRow(0);
            ICell cell = row.CreateCell(0);
            cell.SetCellValue(new XSSFRichTextString("英國  文案工作進度(寄出量化)日報單6月1日後"));

            sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 10));
            cellStyle = workbook.CreateCellStyle();
            font = workbook.CreateFont();
            font.FontName = "宋體";
            font.Boldweight = short.MaxValue;
            // font.FontHeight = 20 * 20;
            font.FontHeightInPoints = 18;
            cellStyle.SetFont(font);
            cellStyle.BorderDiagonalLineStyle = BorderStyle.DashDot;
            cellStyle.Alignment = HorizontalAlignment.Center;
            cell.CellStyle = cellStyle;

            row = sheet.CreateRow(1);
            cell = row.CreateCell(0);
            cell.SetCellValue("寄出個數");
            cell = row.CreateCell(1);
            //if (hnDTOList != null)
            //{
            //    cell.SetCellValue(hnDTOList.Count + "個");
            //}
            cell = row.CreateCell(9);
            cell.SetCellValue("版本:JJLJL-07-2009");
            font.FontHeightInPoints = 11;
            cell.CellStyle = cellStyle;

            //創建文件並寫入
            FileStream file = File.Create("test.xlsx");
            workbook.Write(file);
            string fileName = file.Name;
            file.Close();
            return fileName;
        }
開發者ID:AllanHao,項目名稱:WebSystem,代碼行數:77,代碼來源:ExportHandleNumBPExtend.cs


注:本文中的NPOI.XSSF.UserModel.XSSFWorkbook.GetProperties方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。