Batch Import Multiple Excel Files into FineReport with a Custom Button
This guide explains how to create a custom import button in FineReport that sequentially uploads multiple Excel files, automatically submits previous data, refreshes the page, and ensures the template remains empty for each new import.
When importing data into FineReport, the built‑in Excel import only allows one file at a time and overwrites existing data on the page, making batch imports cumbersome.
The solution is to add a custom Excel import button that, on each click, submits any previously imported data, refreshes the template to a blank state, and then opens the file selector for the next Excel file.
Step 1: Align Excel Headers
Modify the Excel file so that its column titles exactly match the report’s field names, as shown in the example image.
Step 2: Adjust Report Fill Properties
Map the report column to the database column by editing the fill property, e.g., set the category ID to map(C2, "ds2", 2, 1).
Step 3: Add a Custom Import Button
Open Template > Template Web Properties > Fill Page Settings , double‑click the toolbar, and add a new custom button to the top toolbar. Remove the default "Import Excel" and "Submit" buttons.
Step 4: Write the Custom Event Script
Select the custom button in the toolbar editor, click "Custom Event", and insert the following JavaScript code. The script checks whether the current sheet contains data; if it does, it prompts the user to submit the previous import before proceeding.
var value = contentPane.getCellValue(0,1,2);
if (value != "") {
FR.Msg.confirm("提示", "是否提交上一次导入数据", function(result){
if (result) {
_g('${sessionID}').writeReport();
contentPane.refreshAllSheets();
contentPane.importExcel();
}
});
} else {
contentPane.importExcel();
}Using the Custom Button
Click the custom "Import Excel" button, select the first Excel file, and after confirming the prompt, the data is submitted to the database. The file selector then appears again for the next Excel file, repeating the process.
Note that this method only works with a blank template; the template must not contain pre‑existing data. It supports various report styles, but for non‑row‑oriented reports, the control positions must align with the Excel data layout, while row‑oriented reports require matching column titles.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
