Leabharlann .NET saor in aisce do Scarbhileoga Excel®

Léigh, scríobh, ionramháil agus tiontaigh comhaid XLS & XLSX trí leabharlann foinse oscailte .NET.

Cad is NPOI ann?

Is leagan .NET é NPOI de thionscadal POI Java. Is leabharlann foinse oscailte .NET é chun formáidí comhaid Microsoft Excel a léamh agus a scríobh. Soláthraíonn NPOI.HSSF namespace an cumas XLS formáid comhaid a ionramháil, agus NPOI Ligeann .XSSF namespace duit comhaid XLSX a chruthú agus a mhodhnú.

NPOI is a .NET version of POI Java project. It is an open source .NET library to read and write Microsoft Excel file formats. NPOI.HSSF namespace provides the ability to manipulate XLS file format, while NPOI.XSSF namespace allows you to create & modify XLSX files.

NPOI is a .NET version of POI Java project. It is an open source .NET library to read and write Microsoft Excel file formats. NPOI.HSSF namespace provides the ability to manipulate XLS file format, while NPOI.XSSF namespace allows you to create & modify XLSX files.

Ligeann NPOI duit téacs a chur leis, hipearnaisc a chur isteach, cealla & colúin a chruthú & a stíliú, íomhánna a chur isteach agus ábhar ó chomhaid XLS & XLSX atá ann cheana a léamh gan aon spleáchas seachtrach.

Previous Next

Conas NPOI a shuiteáil?

Suiteáil NPOI ó NuGet

 Install-Package NPOI -Version 2.4.1

Ionramháil Comhad XLSX trí C#

Ceadaíonn NPOI do ríomhchláraitheoirí .NET scarbhileoga a chruthú agus a mhodhnú óna bhfeidhmchláir .NET féin. Chun comhad atá ann cheana a mhodhnú, is féidir leat an comhad a luchtú agus téacs, táblaí, stíleanna agus go leor eile a nuashonrú.

Cuir XLSX in eagar le NPOI - C#

IWorkbook wb = new XSSFWorkbook();
// Create a Worksheet
ISheet ws = wb.CreateSheet("FileFormat");
ICellStyle style = wb.CreateCellStyle();
//Setting the line of the top border
style.BorderTop = BorderStyle.Thick;
style.TopBorderColor = 256;
style.BorderLeft = BorderStyle.Thick;
style.LeftBorderColor = 256;
style.BorderRight = BorderStyle.Thick;
style.RightBorderColor = 256;
style.BorderBottom = BorderStyle.Thick;
style.BottomBorderColor = 256;
IRow row = ws.CreateRow(0);
ICell cell = row.CreateCell(1);
cell.CellStyle = style;
FileStream sw = File.Create("fileformat.xlsx");
wb.Write(sw);
sw.Close();

Tiontaigh XLS go XLSX le NPOI

Lean na céimeanna chun an comhad XLS a shábháil mar XLSX tar éis duit é a oscailt agus a mhodhnú le NPOI.

  1. Cruthaigh Leabhar Oibre XSSF nua
  2. Cruthaigh Bileog XSSSF oiriúnach do gach bileog oibre de XLS
  3. Cóipeáil sonraí ó bhileog oibre XLS go bileog oibre XLSX
  4. Cóipeáil an fhormáidiú ó bhileog oibre XLS go bileog oibre XLSX
  5. Sábháil leabhar oibre i bhformáid XLSX

Tiontaigh XLS go XLSX le NPOI - C#

HSSFWorkbook retVal = new HSSFWorkbook();
for (int i = 0; i < source.NumberOfSheets; i++)
{
	HSSFSheet hssfSheet = (HSSFSheet)retVal.CreateSheet(source.GetSheetAt(i).SheetName);
	XSSFSheet xssfsheet = (XSSFSheet)source.GetSheetAt(i);
	CopySheets(xssfsheet, hssfSheet, retVal);
}

Cuir Íomhá le XLSX trí C#

Ligeann an API do na forbróirí íomhánna a chur leis i ndoiciméid scarbhileog. Is féidir leat íomhá a chur leis agus airíonna íomhá a shocrú. Ceadaíonn an API modhanna éagsúla chun íomhánna a ionramháil i bhformáid comhaid XLSX go héasca. Ceadaíonn IClientAnchor duit suíomh barr, bun, clé agus ar dheis na híomhá a shocrú taobh istigh den bhileog oibre.

Cruthaigh Tábla le XSSF NPOI - C#

IWorkbook wb = new XSSFWorkbook();
ISheet sheet1 = wb.CreateSheet("First Sheet");
// Add picture data to this workbook.
byte[] bytes = File.ReadAllBytes("fileformat.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("image.xlsx");
wb.Write(sw);
sw.Close();
 Gaeilge