package com.example.tiwen20;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.service.controls.actions.FloatAction;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.ScriptStyle;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class shengchengbiaoActivity extends AppCompatActivity {
private UserDB stuDao;
private TiwenDB wenDao;
private TiwenBean wenDate;
private UserBean stuDate;
private String name;
private List<TiwenBean> listwendate;
private List<UserBean> liststudate;
private Button daochu;
private Button dakai;
private Log log;
private Context context;
private ListView form_list;
private final int REQUEST_EXTERNAL_STORAGE = 1;
private String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shengchengbiao);
daochu = (Button)findViewById(R.id.export_button);
dakai = (Button)findViewById(R.id.open_button);
Intent intent = getIntent();
liststudate = new ArrayList<>();
listwendate = new ArrayList<>();
name = intent.getStringExtra("name");
stuDao=new UserDB(this);
liststudate=stuDao.queryData(name);
stuDate=liststudate.get(0);
wenDao=new TiwenDB(this);
listwendate=wenDao.queryDataFor(name);
wenDate=listwendate.get(0);
try {
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) &&getAvailableStorage() > 1000000) {
System.out.println("sd卡不可用");
}
else
{
System.out.println("sd卡可用");
}
File file;
File dir = new File(Environment.getExternalStorageDirectory().getPath()+"/export");
if (!dir.exists()) {
dir.mkdirs();
}
file = new File(dir,"excel1.xls");
System.out.println(Environment.getExternalStorageDirectory());
WritableWorkbook wwb;
OutputStream os = new FileOutputStream(file);
wwb = Workbook.createWorkbook(os);
//sheet表标题
WritableSheet wsheet = wwb.createSheet("体温生成表",0);