NPOI Generate Excel with Date Format

Jika kita ingin memasukkan object DateTime ke dalam cell menggunakan NPOI, perlu ada penanganan khusus. [code language=”csharp”] XSSFCellStyle styleDate = (XSSFCellStyle)workbook.CreateCellStyle(); styleDate.DataFormat = workbook.CreateDataFormat().GetFormat("yyyy-mm-dd HH:mm"); XSSFCell cell = (XSSFCell)row.CreateCell(colIndex++); cell.SetCellValue(single.Timestamp); cell.CellStyle = styleDate; [/code] http://stackoverflow.com/questions/3425931/npoi-excel-number-format-not-showing-in-excel-sheet-in-asp-net

NPOI Generate Excel Template for Data Input

Kadang template excel perlu digenerate oleh program. Template dapat digenerate menggunakan NPOI. Berikut contohnya: Controller [code language=”csharp”] public ActionResult GetTemplate(int companyId) { company company = RepoCompany.FindByPk(companyId); string filename = company.name + "-operation-rkap-template.xlsx"; Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo { Filters = new List<Business.Infrastructure.FilterInfo> { new Business.Infrastructure.FilterInfo { Field = "company_id", Operator = "eq", Value = companyId.ToString()…

NPOI Read Excel File

Contoh kode menggunakan lib NPOI untuk membaca file excel (xlsx) [code language=”csharp”] //kamus List<ManufacturerFormStub> ret = new List<ManufacturerFormStub>(); string imagePath = null; //algoritma string currentFilePathInServer = HttpContext.Current.Server.MapPath(FilePath); XSSFWorkbook book; using (FileStream file = new FileStream(currentFilePathInServer, FileMode.Open, FileAccess.Read)) { book = new XSSFWorkbook(file); } XSSFSheet sheet = (XSSFSheet)book.GetSheet("manufacturer"); for (int row = 1; row < sheet.LastRowNum;…

ASP MVC Create/Export Excel using NPOI

Pemrosesan excel menggunakan Excel.Interop di ASP sepertinya bermasalah. 1. Perlu meng-install excel di server 2. Ada potensi error “Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password. (Exception from…

ASP.NET Fetch Image in Excel File

Menggunakan Interop.Excel ternyata mengalami kendala ketika akan mengambil image dari file excel. Banyak website menyarankan menggunakan Interop.Excel dan Clipboard. Solusi tersebut sepertinya berfungsi untuk desktop app, tapi tidak berfungsi di web app. Solusi yang saat ini saya temukan adalah mengganti library dari Interop.Excel menjadi NPOI. NPOI bisa di download menggunakan NuGET. Contoh kode untuk mengambil…