easyexcel 写入oss
时间: 2023-08-19 11:10:59 浏览: 144
您可以使用EasyExcel库将数据写入到OSS(阿里云对象存储)中以下是一个简单的示例代码,演示了如何使用EasyExcel将数据写入到OSS中:
```java
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
public class EasyExcelOSSWriter {
public static void main(String[] args) {
// 配置OSS相关参数
String endpoint = "your_oss_endpoint";
String accessKeyId = "your_access_key_id";
String accessKeySecret = "your_access_key_secret";
String bucketName = "your_bucket_name";
String objectName = "your_object_name"; // 保存的文件名
// 创建ExcelWriterBuilder对象
ExcelWriterBuilder writerBuilder = EasyExcel.write();
// 设置要写入的文件和Sheet
ExcelWriterSheetBuilder sheetBuilder = writerBuilder.sheet("Sheet1");
// 添加数据到Sheet中
sheetBuilder.head("Header1", "Header2", "Header3"); // 设置表头
sheetBuilder.row(1, "Data1", "Data2", "Data3"); // 添加一行数据
sheetBuilder.row(2, "Data4", "Data5", "Data6"); // 添加另一行数据
// 构建ExcelWriter对象
ExcelWriter writer = sheetBuilder.build();
// 将数据写入到OSS中
writer.writeToOss(endpoint, accessKeyId, accessKeySecret, bucketName, objectName);
// 关闭ExcelWriter对象
writer.finish();
}
}
```
在上述代码中,您需要替换以下参数:
- `your_oss_endpoint`:您的OSS的访问地址,***
阅读全文