Browse Source

Merge pull request #35 from ODotNet/standard2.0

fix bugs:issue32
master
Savorboard 7 years ago
committed by GitHub
parent
commit
d227277d85
  1. 40
      samples/Npoi.Samples.CreateNewSpreadsheet/Issue32.cs
  2. 39
      samples/Npoi.Samples.CreateNewSpreadsheet/Issue33.cs
  3. 4
      samples/Npoi.Samples.CreateNewSpreadsheet/Program.cs
  4. 4
      src/NPOI.OpenXml4Net/OPC/ZipPackage.cs

40
samples/Npoi.Samples.CreateNewSpreadsheet/Issue32.cs

@ -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();
}
}
}

39
samples/Npoi.Samples.CreateNewSpreadsheet/Issue33.cs

@ -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
}
}
}
}

4
samples/Npoi.Samples.CreateNewSpreadsheet/Program.cs

@ -16,7 +16,9 @@ namespace Npoi.Samples.CreateNewSpreadsheet
//ExportExcel(); //ExportExcel();
//ExportExcelHSSF(); //ExportExcelHSSF();
//ExportWord(); //ExportWord();
ImportExcelHSSF(); //ImportExcelHSSF();
Issue32.Run();
Console.Read();
} }
private static void ImportExcelHSSF() { private static void ImportExcelHSSF() {

4
src/NPOI.OpenXml4Net/OPC/ZipPackage.cs

@ -343,7 +343,9 @@ namespace NPOI.OpenXml4Net.OPC
{ {
// Either the save operation succeed or not, we delete the // Either the save operation succeed or not, we delete the
// temporary file // temporary file
File.Delete(tempfilePath); //Fixbug:https://github.com/dotnetcore/NPOI/issues/32
//File.Delete(tempfilePath);
fi.Delete();
logger logger
.Log(POILogger.WARN, "The temporary file: '" .Log(POILogger.WARN, "The temporary file: '"

Loading…
Cancel
Save