Java操作Excel表(二)学生表的增删查改

Java操作Excel表(二)学生信息管理系统

上一期

前言

       上一期查看了源码并且实现了读和写的操作以后,这一期就直接拿来做项目了。其中最经典的项目就是学生信息管理系统,有IO实现的,也有SQL实现的,今天这里就是要用Excel来替代前两种方式来实现。

建表

       这里给出四个字段,然后代码里面建立相应的实体类

在这里插入图片描述

字符串模糊查询辅助方法

这里提到过
    public boolean matchStringByIndexOf(String str,String part) {
   
        int count = 0;
        int index = 0;
        while( ( index = str.indexOf(part, index) ) != -1 )
        {
   
            index = index+part.length();
            count++;
        }
        if(count < 1){
   
            return false;
        }
        return true;
    }

全代码

package com.alvin.service.impl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.alvin.domain.ZStudent;
import com.alvin.service.StringUtilService;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import com.alvin.service.ExcelService;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.WriteException;
import jxl.Sheet;
public class ExcelServiceImpl implements ExcelService{
   
    private String fileName = "E:/ExcelProject/student.xls";
    private StringUtilService stringUtilService = new StringUtilServiceImpl();
    /**
     * 添加数据
     * @throws IOException
     * @throws WriteException
     */
    public void writeExcel(ZStudent zStudent) throws Exception {
   
        FileInputStream fileInputStream;
        try {
   
            fileInputStream = new FileInputStream(fileName);
            POIFSFileSystem poifsFileSystem=new POIFSFileSystem(fileInputStream);  //使用POI提供的方法得到excel的信息
            HSSFWorkbook workbook=new HSSFWorkbook(poifsFileSystem);
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值