use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class BarcodeTemplate method add.
public BarcodeTemplate add(String barcode, String descspec) {
DataSet ds = this.getDataSet();
if (ds == null) {
ds = new DataSet();
this.setDataSet(ds);
}
ds.append();
ds.setField("Code_", barcode);
ds.setField("Name_", descspec);
return this;
}
use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class ImportExcel method exportTemplate.
public void exportTemplate() throws IOException, WriteException {
DataSet dataOut = getDataSet();
this.setResponse(response);
// 取得输出流
OutputStream os = response.getOutputStream();
// 清空输出流
response.reset();
template = this.getTemplate();
// 下面是对中文文件名的处理
// 设置相应内容的编码格式
response.setCharacterEncoding("UTF-8");
String fname = URLEncoder.encode(template.getFileName(), "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + fname + ".xls");
// 定义输出类型
response.setContentType("application/msexcel");
List<Column> columns = template.getColumns();
// 创建工作薄
WritableWorkbook workbook = Workbook.createWorkbook(os);
// 创建新的一页
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
// 输出列头
int row = 0;
for (int col = 0; col < columns.size(); col++) {
Column column = columns.get(col);
Label item = new Label(col, row, column.getName());
sheet.addCell(item);
}
// 输出列数据
if (dataOut != null) {
dataOut.first();
while (dataOut.fetch()) {
row++;
for (int col = 0; col < columns.size(); col++) {
Column column = columns.get(col);
column.setRecord(dataOut.getCurrent());
if (column instanceof NumberColumn) {
jxl.write.Number item = new jxl.write.Number(col, row, (double) column.getValue());
sheet.addCell(item);
} else {
Label item = new Label(col, row, (String) column.getValue());
sheet.addCell(item);
}
}
}
}
// 把创建的内容写入到输出流中,并关闭输出流
workbook.write();
workbook.close();
os.close();
}
use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class ImportFile method init.
public int init() throws UnsupportedEncodingException {
dataSet = new DataSet();
// 处理文件上传
DiskFileItemFactory factory = new DiskFileItemFactory();
// 设置最大缓存
factory.setSizeThreshold(5 * 1024);
ServletFileUpload upload = new ServletFileUpload(factory);
try {
uploadFiles = upload.parseRequest(request);
} catch (FileUploadException e) {
// e.printStackTrace();
uploadFiles = null;
return 0;
}
if (uploadFiles != null) {
for (int i = 0; i < uploadFiles.size(); i++) {
FileItem fileItem = uploadFiles.get(i);
if (fileItem.isFormField()) {
// 普通数据
String val = new String(fileItem.getString().getBytes("ISO-8859-1"), "UTF-8");
dataSet.getHead().setField(fileItem.getFieldName(), val);
} else {
// 文件数据
if (fileItem.getSize() > 0) {
Record rs = dataSet.append().getCurrent();
rs.setField("_FieldNo", i);
rs.setField("_FieldName", fileItem.getFieldName());
rs.setField("_ContentType", fileItem.getContentType());
rs.setField("_FileName", fileItem.getName());
rs.setField("_FileSize", fileItem.getSize());
}
}
}
}
dataSet.first();
return dataSet.size();
}
use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class HtmlGridTest method test_getDataSet.
@Test
public void test_getDataSet() {
DataSet ds = new DataSet();
for (int i = 1; i < 3; i++) ds.append().setField("Code", "C00" + i).setField("Name", "N00" + i);
String str = HtmlGrid.getDataSet(ds);
assertTrue(!"".equals(str));
}
use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class DataSetFileTest method testExecute.
@Test
@Ignore(value = "测试文件建立,仅在本地执行")
public void testExecute() throws RowsExceededException, WriteException, IOException {
DataSet ds = new DataSet();
ds.append();
ds.setField("code", "code1");
ds.append();
ds.setField("code", "code2");
String fileName = "d:\\tempfile.xls";
new DataSetFile(ds).save(fileName);
File file = new File(fileName);
assertTrue("文件建立失败!", file.exists());
}
Aggregations