admin 管理员组

文章数量: 887021


2024年1月19日发(作者:google翻译、)

android studio excell读写例程

以下是使用Java语言在Android Studio中实现Excel读写操作的示例代码:

1. 读取Excel文件

java

2.

import ;

import putStream;

import ption;

import ;

import ;

import ;

import ok;

import okFactory;

public class ExcelReader {

public static void readExcel(String filePath) {

try {

FileInputStream inputStream = new FileInputStream(new File(filePath));

Workbook workbook = (inputStream);

Sheet sheet = etAt(0);

for (Row row : sheet) {

for (Cell cell : row) {

(ng() + "t");

}

n();

}

();

();

} catch (IOException e) {

tackTrace();

}

}

}

写入Excel文件

java复制代码

import tputStream;

import ption;

import del.*;

import del.*;

public class ExcelWriter {

public static void writeExcel(String filePath, String[][] data) {

try {

XSSFWorkbook workbook = new XSSFWorkbook();

XSSFSheet sheet = Sheet("Sheet1");

for (int i = 0; i < ; i++) {

Row row = Row(i);

for (int j = 0; j < data[i].length; j++) {

Cell cell = Cell(j);

lValue(data[i][j]);

}

}

FileOutputStream outputStream = new FileOutputStream(new File(filePath));

(outputStream);

();

();

} catch (IOException e) {

tackTrace();

}

}

}


本文标签: 文件 代码 读写操作 示例