xml,Excel文件的读取

     */
    public HotArea readDoc(InputStream inputStream) {
        Document doc = null;
        HotArea root = new HotArea();

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder;
        try {
            builder = factory.newDocumentBuilder();
            doc = builder.parse(inputStream);
            NodeList nodeList = doc.getChildNodes();
            if (nodeList != null && nodeList.getLength() == 1) {
                Node node = nodeList.item(0);
                root = readToPlace(null, node);
            }
        } catch (Exception e) {
            LogUtils.e(TAG, e.getMessage());
        }
        return root;
    }
 public HotArea readToPlace(HotArea placeNode, Node node) {
        HotArea hNode = placeNode;
        if (hNode == null) {
            hNode = new HotArea();
        }
        Element element = (Element) node;
        NamedNodeMap attrs = element.getAttributes();
        int len = attrs.getLength();
        for (int i = 0; i < len; ++i) {
            Node n = attrs.item(i);
            String name = n.getNodeName();
            String value = n.getNodeValue();
            if ("areaId".equals(name)) {
                hNode.setAreaId(value);
            } else if ("areaTitle".equals(name)) {
                hNode.setAreaTitle(value);
            } else if ("pts".equals(name)) {
                hNode.setPts(value, ",");
            } else if ("desc".equals(name)) {
                hNode.setDesc(value);
            }
        }

        NodeList nodeList = element.getChildNodes();
        int jLen = nodeList.getLength();
        for (int j = 0; j < jLen; ++j) {
            Node n = nodeList.item(j);
            if (n instanceof Element) {
                HotArea h = new HotArea();
                hNode.getAreas().add(h);
                readToPlace(h, n);
            }
        }

        return hNode;
    }

参考连接这里写链接内容

Excel表的读取 jxl

生成一个Excel表

{
            Workbook oldWwb = Workbook.getWorkbook(excelFile);
            wwb = Workbook.createWorkbook(excelFile, oldWwb);
            WritableSheet ws = wwb.getSheet(0);
            // 当前行数
            int row = ws.getRows();
            Label lab1 = new Label(0, row, args[0] + "");
            Label lab2 = new Label(1, row, args[1] + "");
            Label lab3 = new Label(2, row, args[2] + "");
            Label lab4 = new Label(3, row, args[3] + "");
            ws.addCell(lab1);
            ws.addCell(lab2);
            ws.addCell(lab3);
            ws.addCell(lab4);

            // 从内存中写入文件中,只能刷一次.
            wwb.write();
            wwb.close();
            Toast.makeText(activity, "保存成功", Toast.LENGTH_SHORT).show();

        }

读取Excel表的数据

/**
     * 获取 excel 表格中的数据,不能在主线程中调用
     *
     * @param xlsName excel 表格的名称
     * @param index   第几张表格中的数据
     */
    private ArrayList<CountryModel> getXlsData(String xlsName, int index) {
        ArrayList<CountryModel> countryList = new ArrayList<CountryModel>();
        AssetManager assetManager = getAssets();

        try {
            Workbook workbook = Workbook.getWorkbook(assetManager.open(xlsName));
            Sheet sheet = workbook.getSheet(index);

            int sheetNum = workbook.getNumberOfSheets();
            int sheetRows = sheet.getRows();
            int sheetColumns = sheet.getColumns();

            Log.d(TAG, "the num of sheets is " + sheetNum);
            Log.d(TAG, "the name of sheet is  " + sheet.getName());
            Log.d(TAG, "total rows is 行=" + sheetRows);
            Log.d(TAG, "total cols is 列=" + sheetColumns);

            for (int i = 0; i < sheetRows; i++) {
                CountryModel countryModel = new CountryModel();
                countryModel.setChinaName(sheet.getCell(0, i).getContents());
                countryModel.setEnglishName(sheet.getCell(1, i).getContents());
                countryModel.setAreaNumber(sheet.getCell(2, i).getContents());

                countryList.add(countryModel);
            }

            workbook.close();

        } catch (Exception e) {
            Log.e(TAG, "read error=" + e, e);
        }

        return countryList;
    }


//在异步方法中 调用
private class ExcelDataLoader extends AsyncTask<String, Void, ArrayList<CountryModel>> {

        @Override
        protected void onPreExecute() {
            progressDialog.setMessage("加载中,请稍后......");
            progressDialog.setCanceledOnTouchOutside(false);
            progressDialog.show();
        }

        @Override
        protected ArrayList<CountryModel> doInBackground(String... params) {
            return getXlsData(params[0], 0);
        }

        @Override
        protected void onPostExecute(ArrayList<CountryModel> countryModels) {
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }

            if(countryModels != null && countryModels.size()>0){
                //存在数据
                sortByName(countryModels);
                setupData(countryModels);
            }else {
                //加载失败


            }

        }
    }

读取的地址
这里写链接内容

裁剪照片

 */  
public void startPhotoZoom(Uri uri) {  
    Intent intent = new Intent("com.android.camera.action.CROP");  
    intent.setDataAndType(uri, "image/*");  
    // crop=true是设置在开启的Intent中设置显示的VIEW可裁剪  
    intent.putExtra("crop", "true");  
    // aspectX aspectY 是宽高的比例  
    intent.putExtra("aspectX", 1);  
    intent.putExtra("aspectY", 1);  
    // outputX outputY 是裁剪图片宽高  
    intent.putExtra("outputX", 300);  
    intent.putExtra("outputY", 300);  
    intent.putExtra("return-data", true);  
    startActivityForResult(intent, REQUESTCODE_CUTTING);  
} 

文字识别 ocr

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值