按钮:<a class="nui-button" iconCls="icon-download" οnclick="expDatas()">导出</a>
<!--导出 -->
<iframe id="excelDownload" style="display: none;"></iframe>
function expDatas(){
var data =grid.getData();//获取grid表格数据
if(data.length<1){
showAlert("提示", "没有数据不能导出!");
return;
}
var json = nui.encode({"param" : data});
nui.ajax({
url : "com.sgai.fssc.service.hec4cwgx.bgt.bgtJournalImport.exportFinancialExcel.biz.ext",
type : "post",
data : json,
cache : false,
contentType : 'text/json',
success : function(text) {
var returnJson = nui.decode(text);
if(returnJson.result=="0"){
if(!text.exception){
var fileName="预算日记账";//导出的名称
//download.jsp是导出后需要进行输出处理
var downloadURL=encodeURI("<%=request.getContextPath()%>/pay/download.jsp?filePath="
+ returnJson.downloadFile
+ "&filename="
+ fileName);
$("#excelDownload").attr("src",downloadURL);
} else {
nui.alert("操作失败!<br/>"+ text.exception.message);
}
}else{
showAlert("失败", "操作失败!");
}
},
error : function() {
showAlert("失败", "请求失败!");
}
});
}
@Bizlet("")
public static String getObjectsToJsonString(DataObject[] obs) {
JSONArray jsonAry = new JSONArray();
JSONObject jsonObj = new JSONObject();
DataObject tmpob = null;
for (int i = 0; i < obs.length; i++) {
tmpob = obs[i];
List<PropertyImpl> properties = tmpob.getInstanceProperties();
Iterator<PropertyImpl> it = properties.iterator();
while (it.hasNext()) {
PropertyImpl property = it.next();
String keystr = property.getName();
String value = tmpob.getString(keystr);
jsonObj.element(keystr, value);
}
jsonAry.add(jsonObj);
}
return jsonAry.toString();
}
拼装数据:
@Bizlet("预算日记账导入")
public List<DataObject> getExcelData(String filePath,int sid,IUserObject [] user,String bgtOrgCode) throws FileNotFoundException, IOException,Exception{
//创建工作簿对象
// 得到工作簿所有的工作表对象
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(new File(filePath)));
HSSFSheet sheet = wb.getSheetAt(0);
// 遍历所有行
List<DataObject> list = new ArrayList<DataObject>();
ITransactionManager m