public class Const {
public interface OrderInfo{
public static final String[][] orderOne = new String[][] {{ "123", "九龙", "13294352311",
"武汉市关山口" },{ "124", "咱家", "13294352312",
"武汉市水果湖" },{ "125", "陈家", "13294352315",
"武汉市华师" },{ "126", "李", "13294352316",
"武汉市杨家湾" }};
}
}
public class Order implements Serializable {
public String id;
public String restPhone;
public String restName;
public String receiverAddr;
public Order(String id,String restPhone, String restName, String receiverAddr) {
this.id = id;
this.restPhone = restPhone;
this.restName = restName;
this.receiverAddr = receiverAddr;
}
}
/** 获取SD可用容量 */
private static long getAvailableStorage(Context context) {
String root = context.getExternalFilesDir(null).getPath();
StatFs statFs = new StatFs(root);
long blockSize = statFs.getBlockSize();
long availableBlocks = statFs.getAvailableBlocks();
long availableSize = blockSize * availableBlocks;
// Formatter.formatFileSize(context, availableSize);
return availableSize;
}
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)&&getAvailableStorage()>1000000) {
Toast.makeText(context, "SD卡不可用", Toast.LENGTH_LONG).show();
return;
}
File file;
File dir = new File(context.getExternalFilesDir(null).getPath());
file = new File(dir, fileName + ".xls");
if (!dir.exists()) {
dir.mkdirs();
}
WritableWorkbook wwb; OutputStream os = new FileOutputStream(file); wwb = Workbook.createWorkbook(os);
WritableSheet sheet = wwb.createSheet("订单", 0);
String[] title = { "订单", "店名", "电话", "地址" };
Label label;
for (int i = 0; i < title.length; i++) {
// Label(x,y,z) 代表单元格的第x+1列,第y+1行, 内容z
// 在Label对象的子对象中指明单元格的位置和内容
label = new Label(i, 0, title[i], getHeader());
// 将定义好的单元格添加到工作表中
sheet.addCell(label);
}
public static WritableCellFormat getHeader() {
WritableFont font = new WritableFont(WritableFont.TIMES, 10,
WritableFont.BOLD);// 定义字体
try {
font.setColour(Colour.BLUE);// 蓝色字体
} catch (WriteException e1) {
e1.printStackTrace();
}
WritableCellFormat format = new WritableCellFormat(font);
try {
format.setAlignment(jxl.format.Alignment.CENTRE);// 左右居中
format.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 上下居中
format.setBorder(Border.ALL, BorderLineStyle.THIN,
Colour.BLACK);// 黑色边框
format.setBackground(Colour.YELLOW);// 黄色背景
} catch (WriteException e) {
e.printStackTrace();
}
return format;
}
for (int i = 0; i < exportOrder.size(); i++) {
Order order = exportOrder.get(i);
Label orderNum = new Label(0, i + 1, order.id);
Label restaurant = new Label(1, i + 1, order.restName);
Label nameLabel = new Label(2,i+1,order.restPhone);
Label address = new Label(3, i + 1, order.receiverAddr);
sheet.addCell(orderNum);
sheet.addCell(restaurant);
sheet.addCell(nameLabel);
sheet.addCell(address);
Toast.makeText(context, "写入成功", Toast.LENGTH_LONG).show();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int length = Const.OrderInfo.orderOne.length;
for(int i = 0;i < length;i++){
Order order = new Order( Const.OrderInfo.orderOne[i][0], Const.OrderInfo.orderOne[i][1], Const.OrderInfo.orderOne[i][2], Const.OrderInfo.orderOne[i][3]);
orders.add(order);
}
btn = (Button)super.findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
ExcelUtil.writeExcel(MainActivity.this,
orders, "excel_"+new Date().toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有