本文整理汇总了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);
}
示例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();
}
示例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);
}
示例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();
}
示例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());
}
示例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;
}