Skip to main content

Posts

Showing posts from May, 2014

C#: Merging Excel cells with NPOI HSSFWorkbook

In this post we’ll see how to merge the two or more cell with each other while creating the excel sheet using NPOI . Mentioned below is code to merge multiple cells, in this example we are merging first cell to fifth cell of first row (you can adjust row or cell range by passing particular parameters in CellRangeAddress). //Created new Workbook var hwb = new NPOI.HSSF.UserModel. HSSFWorkbook (); //Create worksheet with name. var sheet = hwb.CreateSheet( "new sheet" ); //Create row and cell. var row = sheet.CreateRow(0); var cell = row.CreateCell(0); ; //Set text inside cell cell.SetCellValue( "This is Merged cell" ); cell.CellStyle.WrapText = true ; //define cell range address // parameters: -> first row to last and first cell to last cell var cra = new NPOI.SS.Util. CellRangeAddress (0, 0, 0, 4); //Add merged region to sheet. sheet.AddMergedRegion(cra); Hope this solution helps you J

How to fix 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine error

While creating OleDB Connection through Visual Studio (to connect with Access DB or import data from excel or CSV), you may get the error read as: 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. Solutions: There are several possible solutions for this error; you can try any one of mentioned below solution: ·          Try to install MicrosoftAccess Database Engine 2010 Redistributable. ·          If that doesn’t solve your problem try to install 2007Office System Driver: Data Connectivity Components. ·          Or you can try by changing Solution Platform from "Any CPU" to "x86". For this right click on the Solution File(in Solution Explorer) -> Configuration Manager -> Active Platform Drop down -> If x86 is already there then select that, else Click on New -> Select x86 from the new platform dropdown -> Compile and Run your application.