问题:Excel在“xxx.xlsx”中发现不可读取的内容。是否恢复此工作薄的内容?【原创】
现象:

点"是(Y)"

提示信息中提到的error242440_02.xml文件:

问题重现:

package poi; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class FoundUnreadRecord { public static void main(String[] args) throws IOException {
int rowNum = 1;
createExcel_Reference(rowNum);
createExcel_WithTips(rowNum); rowNum = 0;
createExcel_Reference(rowNum);
createExcel_WithTips(rowNum);
} private static void createExcel_Reference(int rowNum) throws FileNotFoundException,
IOException {
String fileName = "UnreadRecordTips_Reference"+rowNum+".xlsx"; XSSFWorkbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("UnreadRecordTips");
for (int i = 0; i <= rowNum; i++) {
Row row = sheet.createRow(i);
Cell cell = row.createCell(0);
cell.setCellValue("test" + i);
} write(fileName, wb);
} private static void createExcel_WithTips(int rowNum) throws FileNotFoundException,
IOException {
String fileName = "UnreadRecordTips"+rowNum+".xlsx";;
XSSFWorkbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("UnreadRecordTips");
for (int i = 0; i <= rowNum; i++) {
Row row = sheet.createRow(i);
Cell cell = row.createCell(0);
cell.setCellValue("test" + i);
sheet.addMergedRegion(new CellRangeAddress(0, rowNum, 0, 0));
}
write(fileName, wb);
} private static void write(String fileName, XSSFWorkbook wb)
throws FileNotFoundException, IOException {
OutputStream stream = new FileOutputStream(fileName);
wb.write(stream);
stream.close();
}
}
package poi; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class MergedRegionReadHiddenValue { private static final String sheetName="mergedRegion"; public static void main(String[] args) throws IOException {
Workbook wb;
wb=new HSSFWorkbook();
String fileName="mergedRegion.xls";
createExcelWithMergedRegion(wb,fileName);
InputStream s=new FileInputStream(fileName);
wb=new HSSFWorkbook(s);
travelSheet(wb, sheetName);
s.close(); System.out.println("xls End.=========================xlsx Begin"); wb=new XSSFWorkbook();
fileName="mergedRegion.xlsx";
createExcelWithMergedRegion(wb,fileName);
s=new FileInputStream(fileName);
wb=new XSSFWorkbook(s);
travelSheet(wb, sheetName);
s.close();
} private static void createExcelWithMergedRegion(Workbook wb,String fileName)
throws FileNotFoundException, IOException { Sheet sheet=wb.createSheet(sheetName);
int lastRowNum=2;
for (int i=0;i<=lastRowNum;i++) {
createRowFillValue(sheet,i);
}
sheet.addMergedRegion(new CellRangeAddress(0, lastRowNum, 0, 0));
write(wb, fileName);
} private static void travelSheet(Workbook wb, String sheetName) {
Sheet sheet;
sheet=wb.getSheet(sheetName);
for (Row row : sheet) {
System.out.println(row.getCell(0).getStringCellValue());
}
} private static void write(Workbook wb, String fileName)
throws FileNotFoundException, IOException {
OutputStream stream=new FileOutputStream(fileName);
wb.write(stream);
stream.close();
} private static void createRowFillValue(Sheet sheet,int rowIdx) {
Row row=sheet.createRow(rowIdx);
Cell cell=row.createCell(0);
cell.setCellValue("CellValue,"+rowIdx+",0");;
} }
OutPut:
CellValue,0,0
CellValue,1,0
CellValue,2,0
xls End.=========================xlsx Begin
CellValue,0,0
CellValue,1,0
CellValue,2,0
生成的Sheet内容示例:

问题:Excel在“xxx.xlsx”中发现不可读取的内容。是否恢复此工作薄的内容?【原创】的更多相关文章
- NPOI “发现 中的部分内容有问题,是否要恢复此工作薄的内容?如果信任此工作薄的来源。。。”的问题的解决方法
网上说的方法是调整Sheet可见和顺序:https://blog.csdn.net/hulihui/article/details/21196951 stackoverflow给出的解释是:单元格存储 ...
- Excel催化剂开源第10波-VSTO开发之用户配置数据与工作薄文件一同存储
在传统的VBA开发中,若是用的是普通加载项方法,是可以存储数据在xlam上的,若用的是Com加载项方法同时是Addins程序级别的项目开发的,配置文件没法保存到工作薄中,一般另外用配置文件来存放供调用 ...
- Excel VBA入门(九)操作工作薄
虽然我前面讲过,在VBA中操作工作薄并不是件明智的事,但有些时候,还是避免不了要这么做.绝大多数情况下,我们要做的是获取到某个工作薄对象,并以此来获得其中的工作表对象,然后再对工作表中的数据进行处理. ...
- Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配
office版本:2016 系统版本:win10 问题描述: 1.桌面新建excel表格后,打开时,提示“Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效.请确定文件未损坏,并且文 ...
- POI导出Excel发现不可读取的内容
环境说明:MyEclipse Tomcat7.0 通过后台查询数据,导出Excel在打开时会出现以下提示: 点击否,则不显示任何内容,点击是,弹出 查看修改记录为: 通过WPS打开不会出现任何提示,可 ...
- POI导出Excel(xls、xlsx均可以,也支持图片)——(三)
Jar包
- DataTable to Excel(使用NPOI、EPPlus将数据表中的数据读取到excel格式内存中)
/// <summary> /// DataTable to Excel(将数据表中的数据读取到excel格式内存中) /// </summary> /// <param ...
- 为Secure Store Service生成新密钥,解决“生成密钥过程中发现错误”的问题
我们集成TFS和SharePoint Server以后,一个最常见的需求是通过SharePoint Server的Excel Service读取TFS报表中的信息,利用Excel Service的强大 ...
- C#读取Excel显示到repeater中
首先需要一个用来存储我们需要显示的内容,防止页面回发丢失(添加时使用) #region 缓存文件 private DataTable excelData; /// <summary> // ...
随机推荐
- Android经常使用UI组件 - TextView
TextView是Android里面用的最多的UI组件,一般使用在须要显示一些信息的时候,其不能输入,仅仅能初始设定或者在程序中改动. 实例:TextViewDemo 执行效果: 代码清单: 布局文件 ...
- XMPP个人信息展示
在现阶段的通信服务中.各种标准都有,因此会出现无法实现相互连通,而XMPP(Extensible Message and presence Protocol)协议的出现.实现了整个及时通信服务协议的互 ...
- 颜色空间RGB与HSV(HSL)的转换
一般的3D编程只需要使用RGB颜色空间就好了,但其实美术人员更多的是使用HSV(HSL),因为可以方便的调整饱和度和亮度. 有时候美术需要程序帮助调整饱和度来达到特定风格的渲染效果,这时候就需要转换颜 ...
- Android:基于Eclipse编译调试系统级应用源代码
一. 概要描述 在使用Eclipse导入android工程源代码以后,我们可以使用ddms调试和跟踪源代码. 本文讲述动态调试源代码和静态调试源代码的两种方法,避免build system. ...
- 【QT相关】对话框相关
为行编辑器限制规则: QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); lineEdit->setValidator(new QRegEx ...
- [Swust OJ 781]--牛喝水
Time limit(ms): 1000 Memory limit(kb): 65535 The cows have a line of 20 water bowls from which the ...
- BZOJ 1004: [HNOI2008]Cards( 置换群 + burnside引理 + 背包dp + 乘法逆元 )
题意保证了是一个置换群. 根据burnside引理, 答案为Σc(f) / (M+1). c(f)表示置换f的不动点数, 而题目限制了颜色的数量, 所以还得满足题目, 用背包dp来计算.dp(x,i, ...
- WebView之2
首先需要添加权限: <uses-permission android:name="android.permission.INTERNET"/> MainActivity ...
- Oracle自带的exception
存储过程中自带的exception: --查询人员资料历史 BEGIN SELECT * INTO Po_Sac01 FROM Sac01 WHERE Aac001 = Pi_Aac001 ); EX ...
- redis(一)简介
啥也不说百度各种简介 推荐一个博客灰常详细的介绍 nosqlfan 接下来发布redis+USE_TCMALLOC 的安装配置,博客好多坑,找一篇好文真心难啊. redis+keepalived ...