本文整理汇总了C#中NPOI.XSSF.UserModel.XSSFWorkbook.GetFontAt方法的典型用法代码示例。如果您正苦于以下问题:C# XSSFWorkbook.GetFontAt方法的具体用法?C# XSSFWorkbook.GetFontAt怎么用?C# XSSFWorkbook.GetFontAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI.XSSF.UserModel.XSSFWorkbook
的用法示例。
在下文中一共展示了XSSFWorkbook.GetFontAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetFontAt
public void TestGetFontAt()
{
XSSFWorkbook workbook = new XSSFWorkbook();
StylesTable styleSource = workbook.GetStylesSource();
short i = 0;
//get default font
IFont fontAt = workbook.GetFontAt(i);
Assert.IsNotNull(fontAt);
//get customized font
XSSFFont customFont = new XSSFFont();
customFont.IsItalic = (true);
int x = styleSource.PutFont(customFont);
fontAt = workbook.GetFontAt((short)x);
Assert.IsNotNull(fontAt);
}
示例2: Test48877
public void Test48877()
{
String text = "Use \n with word wrap on to create a new line.\n" +
"This line finishes with two trailing spaces. ";
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.CreateSheet() as XSSFSheet;
IFont font1 = wb.CreateFont();
font1.Color=((short)20);
IFont font2 = wb.CreateFont();
font2.Color = (short)(FontColor.RED);
IFont font3 = wb.GetFontAt((short)0);
XSSFRow row = sheet.CreateRow(2) as XSSFRow;
XSSFCell cell = row.CreateCell(2) as XSSFCell;
XSSFRichTextString richTextString =
wb.GetCreationHelper().CreateRichTextString(text) as XSSFRichTextString;
// Check the text has the newline
Assert.AreEqual(text, richTextString.String);
// Apply the font
richTextString.ApplyFont(font3);
richTextString.ApplyFont(0, 3, font1);
cell.SetCellValue(richTextString);
// To enable newlines you need Set a cell styles with wrap=true
ICellStyle cs = wb.CreateCellStyle();
cs.WrapText=(true);
cell.CellStyle=(cs);
// Check the text has the
Assert.AreEqual(text, cell.StringCellValue);
// Save the file and re-read it
wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
sheet = wb.GetSheetAt(0) as XSSFSheet;
row = sheet.GetRow(2) as XSSFRow;
cell = row.GetCell(2) as XSSFCell;
Assert.AreEqual(text, cell.StringCellValue);
// Now add a 2nd, and check again
int fontAt = text.IndexOf("\n", 6);
cell.RichStringCellValue.ApplyFont(10, fontAt + 1, font2);
Assert.AreEqual(text, cell.StringCellValue);
Assert.AreEqual(4, (cell.RichStringCellValue as XSSFRichTextString).NumFormattingRuns);
Assert.AreEqual("Use", (cell.RichStringCellValue as XSSFRichTextString).GetCTRst().r[0].t);
String r3 = (cell.RichStringCellValue as XSSFRichTextString).GetCTRst().r[2].t;
Assert.AreEqual("line.\n", r3.Substring(r3.Length - 6));
// Save and re-check
wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
sheet = wb.GetSheetAt(0) as XSSFSheet;
row = sheet.GetRow(2) as XSSFRow;
cell = row.GetCell(2) as XSSFCell;
Assert.AreEqual(text, cell.StringCellValue);
// FileOutputStream out = new FileOutputStream("/tmp/test48877.xlsx");
// wb.Write(out);
// out.Close();
}