我想导出字符串或对象在Android中出色。 而我没有一个好主意。 我该怎么办? 请给我一些关于android export excel的建议。如何在Android中导出excel?
2
A
回答
0
试试这个简单的Excel:https://github.com/centic9/poi-on-android
或者android5xlsx: https://github.com/andruhon/android5xlsx
他们的试验来包装和Android上的重新包装Apache的POI。如果您已经熟悉Apache-POI,这将是一个很好的开始。
我希望这可以帮助,'。
1
- 的gradle添加进口
编译组: 'net.sourceforge.jexcelapi',名称: 'JXL',版本: '2.6'
- 在AndroidManifest.xml文件中添加权限
创建新类ExcelExporter:
import android.os.Environment; import java.io.File; import java.util.Locale; import jxl.Workbook; import jxl.WorkbookSettings; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; public class ExcelExporter { public static void export() { File sd = Environment.getExternalStorageDirectory(); String csvFile = "yourFile.xls"; File directory = new File(sd.getAbsolutePath()); //create directory if not exist if (!directory.isDirectory()) { directory.mkdirs(); } try { //file path File file = new File(directory, csvFile); WorkbookSettings wbSettings = new WorkbookSettings(); wbSettings.setLocale(new Locale(Locale.GERMAN.getLanguage(), Locale.GERMAN.getCountry())); WritableWorkbook workbook; workbook = Workbook.createWorkbook(file, wbSettings); //Excel sheetA first sheetA WritableSheet sheetA = workbook.createSheet("sheet A", 0); // column and row titles sheetA.addCell(new Label(0, 0, "sheet A 1")); sheetA.addCell(new Label(1, 0, "sheet A 2")); sheetA.addCell(new Label(0, 1, "sheet A 3")); sheetA.addCell(new Label(1, 1, "sheet A 4")); //Excel sheetB represents second sheet WritableSheet sheetB = workbook.createSheet("sheet B", 1); // column and row titles sheetB.addCell(new Label(0, 0, "sheet B 1")); sheetB.addCell(new Label(1, 0, "sheet B 2")); sheetB.addCell(new Label(0, 1, "sheet B 3")); sheetB.addCell(new Label(1, 1, "sheet B 4")); // close workbook workbook.write(); workbook.close(); } catch (Exception e) { e.printStackTrace(); } } }
在你MainActivity添加下面的方法:
- 查找执行出口的地方,例如:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
private void askForPermission(String permission, Integer requestCode) { if (ContextCompat.checkSelfPermission(StartMenu.this, permission) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale( StartMenu.this, permission)) { //This is called if user has denied the permission before //In this case I am just asking the permission again ActivityCompat.requestPermissions(StartMenu.this, new String[]{permission}, requestCode); } else { ActivityCompat.requestPermissions(StartMenu.this, new String[]{permission}, requestCode); } } else { Toast.makeText(this, permission + " is already granted.", Toast.LENGTH_SHORT).show(); } }
@Override protected void onResume() { super.onResume(); askForPermission(Manifest.permission.READ_EXTERNAL_STORAGE, READ_EXST); askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, WRITE_EXST); ExcelExporter.export(); }
相关问题
- 1. 如何在GWT中导出excel文件?
- 2. 如何在Excel中导出VBAProject
- 3. 如何C#的datagridview导出到Excel中
- 4. 如何将网页中的Excel导出
- 5. 如何在ASP.NET中导入导出为Excel功能?
- 6. 如何将R中表()的输出导出到Excel中
- 7. ASP.NET Excel导出
- 8. SSRS Excel导出
- 9. 导出到Excel
- 10. 从Excel导出
- 11. 如何在导出到导轨上的excel时添加格式
- 12. 如何阅读导出的Excel文件?
- 13. 如何从PHP导出到Excel(xlsx)
- 14. 我如何获得symfony2导出到Excel
- 15. 如何导出HTML表时到Excel
- 16. 如何将GitHub问题导出到Excel?
- 17. 如何导出到Excel与OPENROWSET函数
- 18. 如何将ExtJS GridPanel导出到Excel?
- 19. 如何将大数据导出到Excel
- 20. 如何将DatagridView导出到Excel
- 21. 如何手动从ReportViewerWebPart导出excel?
- 22. 如何将GridView导出到Excel?
- 23. 轨如何导出数据到excel
- 24. 将Datagridview导出到Excel中的Excel#
- 25. 在iPad上导出到Excel
- 26. excel在客户端导出
- 27. 将SAS导出到Excel中
- 28. 导出到Excel中的LINQ
- 29. 导出到Excel中的PHP
- 30. 如何在excel中导出时不打印重复数据?
好吧,我会尽量it.Thank你。 –