本文整理汇总了C#中NPOI.XSSF.UserModel.XSSFWorkbook.GetCreationHelper方法的典型用法代码示例。如果您正苦于以下问题:C# XSSFWorkbook.GetCreationHelper方法的具体用法?C# XSSFWorkbook.GetCreationHelper怎么用?C# XSSFWorkbook.GetCreationHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI.XSSF.UserModel.XSSFWorkbook
的用法示例。
在下文中一共展示了XSSFWorkbook.GetCreationHelper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
IWorkbook wb = new XSSFWorkbook();
ISheet sheet1 = wb.CreateSheet("First Sheet");
//add picture data to this workbook.
byte[] bytes = File.ReadAllBytes("../../data/aspose.png");
int pictureIdx = wb.AddPicture(bytes, PictureType.PNG);
ICreationHelper helper = wb.GetCreationHelper();
// Create the drawing patriarch. This is the top level container for all shapes.
IDrawing drawing = sheet1.CreateDrawingPatriarch();
// add a picture shape
IClientAnchor anchor = helper.CreateClientAnchor();
//set top-left corner of the picture,
//subsequent call of Picture#resize() will operate relative to it
anchor.Col1 = 3;
anchor.Row1 = 2;
IPicture pict = drawing.CreatePicture(anchor, pictureIdx);
//auto-size picture relative to its top-left corner
pict.Resize();
FileStream sw = File.Create("../../data/image.xlsx");
wb.Write(sw);
sw.Close();
}
示例2: TestCreate
public void TestCreate()
{
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.CreateSheet() as XSSFSheet;
XSSFRow row = sheet.CreateRow(0) as XSSFRow;
XSSFCreationHelper CreateHelper = workbook.GetCreationHelper() as XSSFCreationHelper;
String[] urls = {
"http://apache.org/",
"www.apache.org",
"/temp",
"file:///c:/temp",
"http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
for (int i = 0; i < urls.Length; i++)
{
String s = urls[i];
XSSFHyperlink link = CreateHelper.CreateHyperlink(HyperlinkType.Url) as XSSFHyperlink;
link.Address=(s);
XSSFCell cell = row.CreateCell(i) as XSSFCell;
cell.Hyperlink=(link);
}
workbook = XSSFTestDataSamples.WriteOutAndReadBack(workbook) as XSSFWorkbook;
sheet = workbook.GetSheetAt(0) as XSSFSheet;
PackageRelationshipCollection rels = sheet.GetPackagePart().Relationships;
Assert.AreEqual(urls.Length, rels.Size);
for (int i = 0; i < rels.Size; i++)
{
PackageRelationship rel = rels.GetRelationship(i);
if (rel.TargetUri.IsAbsoluteUri&&rel.TargetUri.IsFile)
Assert.AreEqual(urls[i].Replace("file:///","").Replace("/","\\"),rel.TargetUri.LocalPath);
else
// there should be a relationship for each URL
Assert.AreEqual(urls[i], rel.TargetUri.ToString());
}
// Bugzilla 53041: Hyperlink relations are duplicated when saving XSSF file
workbook = XSSFTestDataSamples.WriteOutAndReadBack(workbook) as XSSFWorkbook;
sheet = workbook.GetSheetAt(0) as XSSFSheet;
rels = sheet.GetPackagePart().Relationships;
Assert.AreEqual(urls.Length, rels.Size);
for (int i = 0; i < rels.Size; i++)
{
PackageRelationship rel = rels.GetRelationship(i);
if (rel.TargetUri.IsAbsoluteUri && rel.TargetUri.IsFile)
Assert.AreEqual(urls[i].Replace("file:///", "").Replace("/", "\\"), rel.TargetUri.LocalPath);
else
// there should be a relationship for each URL
Assert.AreEqual(urls[i], rel.TargetUri.ToString());
}
}
示例3: TestBug55843f
public void TestBug55843f()
{
XSSFWorkbook wb = new XSSFWorkbook();
try
{
XSSFSheet sheet = wb.CreateSheet("test") as XSSFSheet;
XSSFRow row = sheet.CreateRow(0) as XSSFRow;
XSSFRow row2 = sheet.CreateRow(1) as XSSFRow;
XSSFCell cellA2 = row2.CreateCell(0, CellType.Formula) as XSSFCell;
XSSFCell cellB1 = row.CreateCell(1, CellType.Numeric) as XSSFCell;
cellB1.SetCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.GetCreationHelper().CreateFormulaEvaluator() as XSSFFormulaEvaluator;
cellA2.SetCellFormula("IF(B1=0,\"\",IF(B1=10,3,4))");
CellValue Evaluate = formulaEvaluator.Evaluate(cellA2);
System.Console.WriteLine(Evaluate);
Assert.AreEqual("3", Evaluate.FormatAsString());
}
finally
{
wb.Close();
}
}
示例4: TestBug55843
public void TestBug55843()
{
XSSFWorkbook wb = new XSSFWorkbook();
try
{
XSSFSheet sheet = wb.CreateSheet("test") as XSSFSheet;
XSSFRow row = sheet.CreateRow(0) as XSSFRow;
XSSFRow row2 = sheet.CreateRow(1) as XSSFRow;
XSSFCell cellA2 = row2.CreateCell(0, CellType.Formula) as XSSFCell;
XSSFCell cellB1 = row.CreateCell(1, CellType.Numeric) as XSSFCell;
cellB1.SetCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.GetCreationHelper().CreateFormulaEvaluator() as XSSFFormulaEvaluator;
cellA2.SetCellFormula("IF(B1=0,\"\",((ROW()-ROW(A$1))*12))");
CellValue Evaluate = formulaEvaluator.Evaluate(cellA2);
System.Console.WriteLine(Evaluate);
Assert.AreEqual("12", Evaluate.FormatAsString());
cellA2.CellFormula = (/*setter*/"IF(NOT(B1=0),((ROW()-ROW(A$1))*12),\"\")");
CellValue EvaluateN = formulaEvaluator.Evaluate(cellA2);
System.Console.WriteLine(EvaluateN);
Assert.AreEqual(Evaluate.ToString(), EvaluateN.ToString());
Assert.AreEqual("12", EvaluateN.FormatAsString());
}
finally
{
wb.Close();
}
}
示例5: TestMultisheetFormulaEval
public void TestMultisheetFormulaEval()
{
XSSFWorkbook wb = new XSSFWorkbook();
try
{
XSSFSheet sheet1 = wb.CreateSheet("Sheet1") as XSSFSheet;
XSSFSheet sheet2 = wb.CreateSheet("Sheet2") as XSSFSheet;
XSSFSheet sheet3 = wb.CreateSheet("Sheet3") as XSSFSheet;
// sheet1 A1
XSSFCell cell = sheet1.CreateRow(0).CreateCell(0) as XSSFCell;
cell.SetCellType(CellType.Numeric);
cell.SetCellValue(1.0);
// sheet2 A1
cell = sheet2.CreateRow(0).CreateCell(0) as XSSFCell;
cell.SetCellType(CellType.Numeric);
cell.SetCellValue(1.0);
// sheet2 B1
cell = sheet2.GetRow(0).CreateCell(1) as XSSFCell;
cell.SetCellType(CellType.Numeric);
cell.SetCellValue(1.0);
// sheet3 A1
cell = sheet3.CreateRow(0).CreateCell(0) as XSSFCell;
cell.SetCellType(CellType.Numeric);
cell.SetCellValue(1.0);
// sheet1 A2 formulae
cell = sheet1.CreateRow(1).CreateCell(0) as XSSFCell;
cell.SetCellType(CellType.Formula);
cell.CellFormula = (/*setter*/"SUM(Sheet1:Sheet3!A1)");
// sheet1 A3 formulae
cell = sheet1.CreateRow(2).CreateCell(0) as XSSFCell;
cell.SetCellType(CellType.Formula);
cell.CellFormula = (/*setter*/"SUM(Sheet1:Sheet3!A1:B1)");
wb.GetCreationHelper().CreateFormulaEvaluator().EvaluateAll();
cell = sheet1.GetRow(1).GetCell(0) as XSSFCell;
Assert.AreEqual(3.0, cell.NumericCellValue);
cell = sheet1.GetRow(2).GetCell(0) as XSSFCell;
Assert.AreEqual(4.0, cell.NumericCellValue);
}
finally
{
wb.Close();
}
}
示例6: TestSaveLoadNew
public void TestSaveLoadNew()
{
XSSFWorkbook workbook = new XSSFWorkbook();
//check that the default date system is Set to 1900
CT_WorkbookPr pr = workbook.GetCTWorkbook().workbookPr;
Assert.IsNotNull(pr);
Assert.IsTrue(pr.IsSetDate1904());
Assert.IsFalse(pr.date1904, "XSSF must use the 1900 date system");
ISheet sheet1 = workbook.CreateSheet("sheet1");
ISheet sheet2 = workbook.CreateSheet("sheet2");
workbook.CreateSheet("sheet3");
IRichTextString rts = workbook.GetCreationHelper().CreateRichTextString("hello world");
sheet1.CreateRow(0).CreateCell((short)0).SetCellValue(1.2);
sheet1.CreateRow(1).CreateCell((short)0).SetCellValue(rts);
sheet2.CreateRow(0);
Assert.AreEqual(0, workbook.GetSheetAt(0).FirstRowNum);
Assert.AreEqual(1, workbook.GetSheetAt(0).LastRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(1).FirstRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(1).LastRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(2).FirstRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(2).LastRowNum);
FileInfo file = TempFile.CreateTempFile("poi-", ".xlsx");
Stream out1 = File.OpenWrite(file.Name);
workbook.Write(out1);
out1.Close();
// Check the namespace Contains what we'd expect it to
OPCPackage pkg = OPCPackage.Open(file.ToString());
PackagePart wbRelPart =
pkg.GetPart(PackagingUriHelper.CreatePartName("/xl/_rels/workbook.xml.rels"));
Assert.IsNotNull(wbRelPart);
Assert.IsTrue(wbRelPart.IsRelationshipPart);
Assert.AreEqual(ContentTypes.RELATIONSHIPS_PART, wbRelPart.ContentType);
PackagePart wbPart =
pkg.GetPart(PackagingUriHelper.CreatePartName("/xl/workbook.xml"));
// Links to the three sheets, shared strings and styles
Assert.IsTrue(wbPart.HasRelationships);
Assert.AreEqual(5, wbPart.Relationships.Size);
// Load back the XSSFWorkbook
workbook = new XSSFWorkbook(pkg);
Assert.AreEqual(3, workbook.NumberOfSheets);
Assert.IsNotNull(workbook.GetSheetAt(0));
Assert.IsNotNull(workbook.GetSheetAt(1));
Assert.IsNotNull(workbook.GetSheetAt(2));
Assert.IsNotNull(workbook.GetSharedStringSource());
Assert.IsNotNull(workbook.GetStylesSource());
Assert.AreEqual(0, workbook.GetSheetAt(0).FirstRowNum);
Assert.AreEqual(1, workbook.GetSheetAt(0).LastRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(1).FirstRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(1).LastRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(2).FirstRowNum);
Assert.AreEqual(0, workbook.GetSheetAt(2).LastRowNum);
sheet1 = workbook.GetSheetAt(0);
Assert.AreEqual(1.2, sheet1.GetRow(0).GetCell(0).NumericCellValue, 0.0001);
Assert.AreEqual("hello world", sheet1.GetRow(1).GetCell(0).RichStringCellValue.String);
}
示例7: Test48325
public void Test48325()
{
XSSFWorkbook wb = new XSSFWorkbook();
ISheet sheet = wb.CreateSheet("Test");
ICreationHelper factory = wb.GetCreationHelper();
IRow row = sheet.CreateRow(0);
ICell cell = row.CreateCell(0);
IFont font = wb.CreateFont();
IRichTextString rts = factory.CreateRichTextString("");
rts.ApplyFont(font);
cell.SetCellValue(rts);
sheet.AutoSizeColumn(0);
}
示例8: TestInvalidURLs
public void TestInvalidURLs()
{
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFCreationHelper CreateHelper = workbook.GetCreationHelper() as XSSFCreationHelper;
String[] invalidURLs = {
"http:\\apache.org",
"www.apache .org",
"c:\\temp",
"\\poi"};
foreach (String s in invalidURLs)
{
try
{
CreateHelper.CreateHyperlink(HyperlinkType.Url).Address = (s);
Assert.Fail("expected ArgumentException: " + s);
}
catch (ArgumentException)
{
}
}
}
示例9: TestGetErrorCellValueFromFormulaCell
public void TestGetErrorCellValueFromFormulaCell()
{
XSSFWorkbook wb = new XSSFWorkbook();
ISheet sheet = wb.CreateSheet();
IRow row = sheet.CreateRow(0);
ICell cell = row.CreateCell(0);
cell.SetCellFormula("SQRT(-1)");
wb.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(cell);
Assert.AreEqual(36, cell.ErrorCellValue);
}
示例10: 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();
}
示例11: TestCommentShowsBox
public void TestCommentShowsBox()
{
XSSFWorkbook wb = new XSSFWorkbook();
wb.CreateSheet();
XSSFSheet sheet = (XSSFSheet)wb.GetSheetAt(0);
XSSFCell cell = (XSSFCell)sheet.CreateRow(0).CreateCell(0);
XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch();
XSSFCreationHelper factory = (XSSFCreationHelper)wb.GetCreationHelper();
XSSFClientAnchor anchor = (XSSFClientAnchor)factory.CreateClientAnchor();
anchor.Col1 = cell.ColumnIndex;
anchor.Col2 = cell.ColumnIndex + 3;
anchor.Row1 = cell.RowIndex;
anchor.Row2 = cell.RowIndex + 5;
XSSFComment comment = (XSSFComment)drawing.CreateCellComment(anchor);
XSSFRichTextString str = (XSSFRichTextString)factory.CreateRichTextString("this is a comment");
comment.String = str;
cell.CellComment = comment;
XSSFVMLDrawing vml = sheet.GetVMLDrawing(false);
CT_Shapetype shapetype = null;
ArrayList items = vml.GetItems();
foreach (object o in items)
if (o is CT_Shapetype)
shapetype = (CT_Shapetype)o;
Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.stroked);
Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.filled);
using (MemoryStream ws = new MemoryStream())
{
wb.Write(ws);
using (MemoryStream rs = new MemoryStream(ws.GetBuffer()))
{
wb = new XSSFWorkbook(rs);
sheet = (XSSFSheet)wb.GetSheetAt(0);
vml = sheet.GetVMLDrawing(false);
shapetype = null;
items = vml.GetItems();
foreach (object o in items)
if (o is CT_Shapetype)
shapetype = (CT_Shapetype)o;
//wb.Write(new FileStream("comments.xlsx", FileMode.Create));
//using (MemoryStream ws2 = new MemoryStream())
//{
// vml.Write(ws2);
// throw new System.Exception(System.Text.Encoding.UTF8.GetString(ws2.GetBuffer()));
//}
Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.stroked);
Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.filled);
}
}
}
示例12: Write
public void Write(TestTable table, string outFile)
{
var book = new XSSFWorkbook();
var sheet = book.CreateSheet("data");
//BorderStyle
var borderStyle = book.CreateCellStyle();
borderStyle.BorderTop = BorderStyle.Thin;
borderStyle.BorderLeft = BorderStyle.Thin;
borderStyle.BorderBottom = BorderStyle.Thin;
borderStyle.BorderRight = BorderStyle.Thin;
//style for DATE-Cell
var dateStyle = book.CreateCellStyle();
dateStyle.BorderTop = BorderStyle.Thin;
dateStyle.BorderLeft = BorderStyle.Thin;
dateStyle.BorderBottom = BorderStyle.Thin;
dateStyle.BorderRight = BorderStyle.Thin;
dateStyle.DataFormat = book.GetCreationHelper().CreateDataFormat().GetFormat("yyyy/mm/dd");
for (int r = 0; r < table.RowCount; r++)
{
var datarow = table.GetNextRow();
var destRow = sheet.CreateRow(r);
ICell cell;
var cellType = CellType.Blank;
var colNum = 0;
//STRING-Column
//col1
cellType = CellType.String;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col1);
cell.CellStyle = borderStyle;
colNum++;
//col2
cellType = CellType.String;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col2);
cell.CellStyle = borderStyle;
colNum++;
//col3
cellType = CellType.String;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col3);
cell.CellStyle = borderStyle;
colNum++;
//col4
cellType = CellType.String;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col4);
cell.CellStyle = borderStyle;
colNum++;
//col5
cellType = CellType.String;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col5);
cell.CellStyle = borderStyle;
colNum++;
//NUMBER-Column
//col6
cellType = CellType.Numeric;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col6);
cell.CellStyle = borderStyle;
colNum++;
//col7
cellType = CellType.Numeric;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col7);
cell.CellStyle = borderStyle;
colNum++;
//col8
cellType = CellType.Numeric;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col8);
cell.CellStyle = borderStyle;
colNum++;
//col9
cellType = CellType.Numeric;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col9);
cell.CellStyle = borderStyle;
colNum++;
//col10
cellType = CellType.Numeric;
cell = destRow.CreateCell(colNum);
cell.SetCellType(cellType);
cell.SetCellValue(datarow.Col10);
cell.CellStyle = borderStyle;
colNum++;
//DATE-Column
//col11
//.........这里部分代码省略.........
示例13: TestBug56820_Formula2
public void TestBug56820_Formula2()
{
IWorkbook wb = new XSSFWorkbook();
try
{
IFormulaEvaluator Evaluator = wb.GetCreationHelper().CreateFormulaEvaluator();
ISheet sh = wb.CreateSheet();
sh.CreateRow(0).CreateCell(0).SetCellValue(0.0d);
ICell formulaCell1 = sh.CreateRow(1).CreateCell(0);
ICell formulaCell2 = sh.CreateRow(2).CreateCell(0);
formulaCell1.CellFormula = (/*setter*/FORMULA2);
formulaCell2.CellFormula = (/*setter*/FORMULA2);
double A1 = Evaluator.Evaluate(formulaCell1).NumberValue;
double A2 = Evaluator.Evaluate(formulaCell2).NumberValue; //<-- FAILS EVALUATION
Assert.AreEqual(2, A1, 0);
Assert.AreEqual(4, A2, 0);
}
finally
{
wb.Close();
}
}
示例14: TestBug56527
public void TestBug56527()
{
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.CreateSheet() as XSSFSheet;
XSSFCreationHelper creationHelper = wb.GetCreationHelper() as XSSFCreationHelper;
XSSFHyperlink hyperlink;
// Try with a cell reference
hyperlink = creationHelper.CreateHyperlink(HyperlinkType.Url) as XSSFHyperlink;
sheet.AddHyperlink(hyperlink);
hyperlink.Address = (/*setter*/"http://myurl");
hyperlink.SetCellReference(/*setter*/"B4");
Assert.AreEqual(3, hyperlink.FirstRow);
Assert.AreEqual(1, hyperlink.FirstColumn);
Assert.AreEqual(3, hyperlink.LastRow);
Assert.AreEqual(1, hyperlink.LastColumn);
// Try with explicit rows / columns
hyperlink = creationHelper.CreateHyperlink(HyperlinkType.Url) as XSSFHyperlink;
sheet.AddHyperlink(hyperlink);
hyperlink.Address = (/*setter*/"http://myurl");
hyperlink.FirstRow = (/*setter*/5);
hyperlink.FirstColumn = (/*setter*/3);
Assert.AreEqual(5, hyperlink.FirstRow);
Assert.AreEqual(3, hyperlink.FirstColumn);
Assert.AreEqual(5, hyperlink.LastRow);
Assert.AreEqual(3, hyperlink.LastColumn);
}
示例15: ExportToXLS
public bool ExportToXLS(string filePath)
{
var workBook = new XSSFWorkbook();
var ch = workBook.GetCreationHelper();
var sheet = workBook.CreateSheet();
var cs = workBook.CreateCellStyle();
cs.WrapText = true;
int rowNumber = 0;
sheet.SetColumnWidth(0, 256 * 40);
sheet.SetColumnWidth(1, 256 * 10);
sheet.SetColumnWidth(2, 256 * 90);
sheet.SetColumnWidth(3, 256 * 90);
foreach (var labelGroup in KKLabelGroupsToTranslate)
{
var row = sheet.CreateRow(rowNumber);
// Label Name
var labelCell = row.CreateCell(0);
labelCell.SetCellValue(labelGroup.Name);
// Nametag Text
var nametagCell = row.CreateCell(1);
nametagCell.SetCellValue(labelGroup.NameTag);
// English text
var engCell = row.CreateCell(2);
engCell.SetCellValue(ch.CreateRichTextString(labelGroup.TranslatedText));
engCell.CellStyle = cs;
// Japanese text
var jpCell = row.CreateCell(3);
jpCell.SetCellValue(ch.CreateRichTextString(labelGroup.PrintedText));
jpCell.CellStyle = cs;
//row.Height = 256 * 4;
rowNumber++;
}
try
{
using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
workBook.Write(stream);
}
}
catch (IOException e)
{
return false;
}
return true;
}