【发布时间】:2015-08-21 09:34:15
【问题描述】:
谁能帮帮我
在安卓应用程序中显示一个取自资产文件夹的 excel 文件
我无法显示文件。 我也使用 POI jar 文件来显示该文件...请把代码发给我
我尝试使用 sd 卡,但我无法使用资产
public class MainActivity extends Activity
{
String dbStr = Environment.getExternalStorageDirectory() + "/dropbox/xls/stock1.xls";
String strHyouji="";
String[][] arrays = read();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(arrays == null)
{
strHyouji="no such file";
}
else
{
for (String[] array : arrays)
{
for (String v : array)
{
strHyouji = strHyouji + v + ",";
}
strHyouji = strHyouji + "\n";
}
}
TextView textSetting = (TextView) findViewById(R.id.textView1);
textSetting.setText(strHyouji);
}
public String[][] read()
{
Workbook workbook = null;
try
{
WorkbookSettings ws = new WorkbookSettings();
ws.setGCDisabled(true);
workbook = Workbook.getWorkbook(new File(dbStr), ws);
Sheet sheet = workbook.getSheet(0);
int rowCount = sheet.getRows();
String[][] result = new String[rowCount][];
for (int i = 0; i < rowCount; i++)
{
Cell[] row = sheet.getRow(i);
result[i] = new String[row.length];
for (int j = 0; j < row.length; j++)
{
result[i][j] = row[j].getContents();
}
}
return result;
}
catch (BiffException e)
{
strHyouji=strHyouji+ e.toString();
}
catch (IOException e)
{
strHyouji=strHyouji+ e.toString();
}
catch (Exception e)
{
strHyouji=strHyouji+ e.toString();
}
finally
{
if (workbook != null)
{
workbook.close();
}
}
return null;
}
}
邮箱:ravitejabrt@gmail.com
【问题讨论】:
标签: android excel android-activity android-assets