Chandra Oemaryadi has written 244 articles

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()…

ASP MVC Return View as String

Fungsi berikut untuk mengembalikan hasil render View dalam format string. Nanti ditambahkan ke project template. [code language=”csharp”] public string RenderRazorViewToString(string viewName, object model) { ViewData.Model = model; using (var sw = new StringWriter()) { var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View); return sw.GetStringBuilder().ToString(); }…

Kendo DropDownList using Static DataSource

Contoh kode kendo DropDownList menggunakan DataSource variabel javascript statik. Isi dropdown (#ParentId) berubah sesuai isi #CompanyId. [code language=”javascript”] var dataSource; $(document).ready(function () { var companyId = $(‘#CompanyId’).val(); dataSource = new kendo.data.DataSource({ data: @Html.Raw(Model.AccountOperationsJson), filter: { field: ‘CompanyId’, operator: ‘eq’, value: (companyId / 1) } }); $(‘#ParentId’).kendoDropDownList({ dataTextField: ‘NameUnit’, dataValueField: ‘Id’, dataSource: dataSource, optionLabel: ‘- tidak…

Kendo NumericTextBox OnChange Problem

Saya mengalami kasus yang cukup unik. Kendo NumericTextBox ketika ditulis, lalu keluar, format nya tidak berubah (misal menulis 1000, format tetap 1000, padahal harusnya 1.000). Waktu diklik tombol up/down, nilainya kembali ke awal. Solusi masalah ini adalah dengan me-restart browser. Setelah di-restart, kemungkinan NumericTextBox akan kembali normal.

Entity Framework Repository Pattern Custom Filter using Dynamic Linq

Berikut adalah contoh penanganan filter custom menggunakan repository pattern dan Dynamic Linq. Misalnya untuk kasus many-to-many, atau filter berdasarkan atribut lain dari tabel foreign key. RemoveFilterField dan Clone adalah fungsi tambahan pada kelas FilterInfo [code language=”csharp”] public List<post> Find(int? skip = null, int? take = null, List<SortingInfo> sortings = null, FilterInfo filters = null, bool…

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.NET MVC Upload Large File

Supaya bisa meng-upload file dalam ukuran besar, tambahkan baris ini di web.config [code language=”xml”] <configuration> … <location path="FileManagement"> <system.web> <httpRuntime executionTimeout="50000" maxRequestLength="40000" /> </system.web> </location> </configuration> [/code] Path adalah url, BUKAN FOLDER. Contoh di atas digunakan untuk upload file ke FileManagemenet/Save. Setting seperti ini dapat digunakan pada server dev Pertamina, belum dicoba untuk server production.

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…