Savorboard
7 years ago
committed by
GitHub
4 changed files with 85 additions and 2 deletions
@ -0,0 +1,40 @@ |
|||||
|
|
||||
|
using NPOI.HSSF.UserModel; |
||||
|
using NPOI.SS.UserModel; |
||||
|
using NPOI.XSSF.UserModel; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.IO; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Npoi.Samples.CreateNewSpreadsheet |
||||
|
{ |
||||
|
public class Issue32 |
||||
|
{ |
||||
|
public static void Run() |
||||
|
{ |
||||
|
new Issue32().ReadExcel(); |
||||
|
} |
||||
|
|
||||
|
public void ReadExcel() |
||||
|
{ |
||||
|
//using (var file = new FileStream(@"D:\GitStorage\Npoi.Core\samples\Npoi.Samples.CreateNewSpreadsheet\template.xlsx", FileMode.Open, FileAccess.Read))
|
||||
|
//{
|
||||
|
// var excel = new XSSFWorkbook(file);
|
||||
|
// var cell = excel.GetSheetAt(0).GetRow(0).GetCell(0);
|
||||
|
// Console.WriteLine(cell.NumericCellValue);
|
||||
|
//}
|
||||
|
|
||||
|
//using (var file = new FileStream(@"D:\GitStorage\Npoi.Core\samples\Npoi.Samples.CreateNewSpreadsheet\template.xls", FileMode.Open, FileAccess.Read))
|
||||
|
//{
|
||||
|
// var excel = new HSSFWorkbook(file);
|
||||
|
// var cell = excel.GetSheetAt(0).GetRow(1).GetCell(2);
|
||||
|
// Console.WriteLine(cell.NumericCellValue);
|
||||
|
//}
|
||||
|
|
||||
|
string filePath = $@"D:\GitStorage\Npoi.Core\samples\Npoi.Samples.CreateNewSpreadsheet\template.xlsx"; |
||||
|
IWorkbook workbook = WorkbookFactory.Create(filePath); |
||||
|
workbook.Close(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
using NPOI.XSSF.UserModel; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.IO; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Npoi.Samples.CreateNewSpreadsheet |
||||
|
{ |
||||
|
class Issue33 |
||||
|
{ |
||||
|
public static void Run() |
||||
|
{ |
||||
|
var issue33 = new Issue33(); |
||||
|
issue33.WriteExcel(); |
||||
|
} |
||||
|
|
||||
|
public void WriteExcel() |
||||
|
{ |
||||
|
string outputFileName = $@"D:\GitStorage\Npoi.Core\samples\Npoi.Samples.CreateNewSpreadsheet\template-{DateTime.Now.Ticks.ToString()}.xlsx"; |
||||
|
using (var templateStream =new FileStream(@"D:\GitStorage\Npoi.Core\samples\Npoi.Samples.CreateNewSpreadsheet\template.xlsx", FileMode.Open, FileAccess.Read)) |
||||
|
{ |
||||
|
var excel = new XSSFWorkbook(templateStream); |
||||
|
var cell = excel.GetSheetAt(0).GetRow(2).GetCell(2); |
||||
|
cell.SetCellValue("Issue 33"); |
||||
|
|
||||
|
using (var outputStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write)) |
||||
|
{ |
||||
|
excel.Write(outputStream); |
||||
|
} |
||||
|
} |
||||
|
using (var outputStream = File.OpenRead(outputFileName)) |
||||
|
{ |
||||
|
var excel = new XSSFWorkbook(outputStream); |
||||
|
var cell = excel.GetSheetAt(0).GetRow(2).GetCell(2); |
||||
|
Console.WriteLine(cell.ToString()); //here can console Issue 33
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue