PHP MySQL到PHPExcel没有显示数据

时间:2015-12-14 19:41:14

标签: php phpexcel

/ *它可以工作但是当我打开excel表时它不起作用所以我删除了else语句中的echo和其他所有它所以它工作但没有将数据打印到表单中* /

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.text4);
    text = (TextView)findViewById(R.id.info2);
    BufferedReader reader = null;

    try {
        reader = new BufferedReader(
                new InputStreamReader(getAssets().open("input3.txt")));

        String line;

        List<String> sentences = new ArrayList<String>();

        for ( String line2; (line2 = reader.readLine()) != null;) {

            for (String sentence : line2.split("(?<=[.?!\t])")) {
                sentence = sentence.trim();
                if (! sentence.isEmpty()) {
                    sentences.add(sentence);
                }                   
            }  

            String[] keys = line2.split(" ");
            String[] uniqueKeys;

            int count = 0;
            uniqueKeys = getUniqueKeys(keys);

            for(String key: uniqueKeys)
            {
                if(null == key)
                {
                    break;
                }           
                for(String s : keys)
                {
                    if(key.equals(s))
                    {
                        count++;
                    }               
                }

                if(key.equals("a") || key.equals("the")|| key.equals("is")|| key.equals("of")|| key.equals("and")|| key.equals("The") || key.equals("some") || key.equals("on") || key.equals("during") || key.equals("to") || key.equals("since") || key.equals("in") || key.equals("by") || key.equals("for") || key.equals("were") ||key.equals("--") || key.equals("in") || key.equals("as") || key.equals("that") || key.equals("may") || key.equals("can") || key.equals("without") || key.equals("You")){
                    count = 0;
                }

                if(count >1 ){

                    MyKey = key;


                    Pattern word = Pattern.compile("\\b"+key+"\\b", Pattern.CASE_INSENSITIVE);

                    //sentences is the arrayList of sentences in this program
                    LinkedHashSet<String> lhs = new LinkedHashSet<String>();
                    for (String sentence : sentences) {
                        //checks the occurance of keyword within each sentence 
                        if (word.matcher(sentence).find()) {


                            lhs.add(sentence);


                        }                                          

                    }
                    for (String sentence2 : lhs) {
                        text.append(sentence2);                                     
                    }


                }
                count=0;
            }   


        }


    } catch (IOException e) {
         Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
         e.printStackTrace();
    }finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                //log the exception
            }            

        }

    }







}

1 个答案:

答案 0 :(得分:0)

两件事:

在此代码中

$activeSheet->setCellValue('A1',' $row["firstname"]');

声明,您不应在$row部分周围使用任何引号,将其删除:

$activeSheet->setCellValue('A1', $row["firstname"]);

此外,您的else子句在标头之前输出数据,导致发送不正确的数据。删除else。如果没有数据,您最终会得到一个空的Excel文件。

最后,您将所有数据一遍又一遍地放在相同的单元格中。使用变量递增到rownumber:

$i = 1;
while ($row = ...) {
    ...
    $activeSheet->setCellValue('A'+$i, $row["firstname"]);
    ...
    $i++;
}