码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA日报

时间:2021-06-21 20:14:23      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:对象   null   tor   sdcard   否则   throw   nts   directory   reflect   

从零开始的体温app开发(exceldao)

package Exceldao;
import java.io.File;
import java.lang.reflect.Array;
import java.util.ArrayList;

import Excelutil.util;
import bean.User;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

public class dao {
// 准备设置excel工作表的标题
private WritableSheet sheet;
/**创建Excel工作薄*/
private WritableWorkbook wwb;
private String[] title = { "" };
public dao() {
}
public void excelCreate( Context context) {
try {
// /**输出的excel文件的路径*/
// String filePath =context.getFilesDir().toString()+"/Rec";
// File file = new File(filePath,"temp.xls");
// if(!file.getParentFile().exists()) {
// file.getParentFile().mkdirs();
// }
// if(!file.exists()){
// file.createNewFile();
// }//内部
// File file = new File(context.getExternalFilesDir(null).getPath() + "/Record","tem.xls");
// if(!file.getParentFile().exists()) {
// file.getParentFile().mkdirs();
// }
// if(!file.exists()){
// file.createNewFile();
// }//外部
String fileName=context.getExternalFilesDir(null).getPath() + "/Record";
util.initExcel(fileName,title,context);
}
catch (Exception e) {
e.printStackTrace();
}
}
public void saveDataToExcel(int index, String[] content) throws Exception {
Label label;
for (int i = 0; i < title.length; i++) {
/**Label(x,y,z)其中x代表单元格的第x+1列,第y+1行, 单元格的内容是y
* 在Label对象的子对象中指明单元格的位置和内容
* */
label = new Label(i, 0, title[i]);
/**将定义好的单元格添加到工作表中*/
sheet.addCell(label);
}
/*
* 把数据填充到单元格中
* 需要使用jxl.write.Number
* 路径必须使用其完整路径,否则会出现错误
*/
for (int i = 0; i < title.length; i++) {
Label labeli = new Label(i, index, content[i]);
sheet.addCell(labeli);
}
// 写入数据
wwb.write();
// 关闭文件
wwb.close();
}
private String getSDPath() {
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED);
if (sdCardExist) {
sdDir = Environment.getExternalStorageDirectory();
}
String dir = sdDir.toString();
return dir;
}
}

JAVA日报

标签:对象   null   tor   sdcard   否则   throw   nts   directory   reflect   

原文地址:https://www.cnblogs.com/mumulailai/p/14909477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!