今日总结

2021年3月8日:

今天修改了提交的代码,增加了跳转导入成功的界面以及导入成功后跳转界面的代码,以及增加了导入的代码,但是现在还没成功

package com.example.myapplication;
import android.content.Intent;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class Tijiao extends AppCompatActivity {
private shujuku shuju;
public SQLiteDatabase db;
private List<studenttiwen> students=null;
int startRowIndex=9;
private Button daoru;
private long exitTime = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tijiao);
shuju=new shujuku(this,"tiwenapp.db",null,1);
db=shuju.getReadableDatabase();
daoru=(Button)findViewById(R.id.daoru);
daoru.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor cursor = db.rawQuery("select id,app.name,banji,tiwen,date,address,phone,special from student left join app on app.name=student.name" ,null);
if(cursor.moveToFirst()){
students=new ArrayList<>();
do{
studenttiwen student = new studenttiwen();
student.id = cursor.getString(cursor.getColumnIndex("id"));
student.name = cursor.getString(cursor.getColumnIndex("name"));
student.banji = cursor.getString(cursor.getColumnIndex("banji"));
student.tiwen = cursor.getString(cursor.getColumnIndex("tiwen"));
student.date = cursor.getString(cursor.getColumnIndex("date"));
student.address = cursor.getString(cursor.getColumnIndex("address"));
student.phone = cursor.getString(cursor.getColumnIndex("phone"));
student.special = cursor.getString(cursor.getColumnIndex("special"));
students.add(student);
}while(cursor.moveToNext());
}
cursor.close();
if(students!=null){
AssetManager assets = getApplicationContext().getAssets();
InputStream fis1= null;
try {
fis1 = assets.open("信1905-2学生登记表.xls");
} catch (IOException e) {
e.printStackTrace();
}
HSSFWorkbook workbook = null;
try {
workbook = new HSSFWorkbook(fis1);
} catch (IOException e) {
e.printStackTrace();
}
Sheet sheet = workbook.getSheetAt(0);
for(studenttiwen stu:students){
for(int i=1;i<4;i++){
if(i==1){
Row row=sheet.getRow(1);
row.createCell(1).setCellValue(stu.banji);
row.createCell(5).setCellValue(stu.date);
}
if(i==2){
Row row=sheet.getRow(2);
row.createCell(1).setCellValue(stu.name);
row.createCell(3).setCellValue(stu.id);
}
if(i==3)
{
Row row=sheet.getRow(3);
if(stu.special.equals("无")){
row.createCell(1).setCellValue("正常");
}
else
{
row.createCell(1).setCellValue("异常");
}
row.createCell(3).setCellValue(stu.phone);
}
}
Row row=sheet.getRow(startRowIndex++);
row.createCell(1).setCellValue(stu.tiwen);
if(stu.special.equals("无")){
row.createCell(2).setCellValue("目前为止一切正常");
}
else
{
row.createCell(2).setCellValue("出现异常,正在进行诊治");
}
row.createCell(3).setCellValue(stu.address);
row.createCell(4).setCellValue(stu.special);
}
try {
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Intent intent = new Intent();
intent.setClass(Tijiao.this,Daoru.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if ((System.currentTimeMillis() - exitTime) > 2000){
Toast.makeText(getApplicationContext(), "再按一次返回桌面", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else{
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
}
原文地址:https://www.cnblogs.com/yitiaokuailedexiaojingyu/p/14502083.html