PDA

View Full Version : راهنمای در مورد ساخت یک app ساده



gilar1360
دوشنبه 13 بهمن 1393, 14:06 عصر
یک app می خواهم برای یکی بنویسیم که لیست ویو ساده می خواهد و یه فایل اکسل به عنوان ورودی که دو ستون نام کالا و تعداد را داره می خواهم ببینم میشه فایل اکسل را در یک اپ نمایش داد اگه نمونه کد هستی ممنون میشم

pcpsoft
دوشنبه 13 بهمن 1393, 14:36 عصر
AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.andexcelread0"

android:versionCode="1"

android:versionName="1.0" >



<uses-sdk

android:minSdkVersion="8"

android:targetSdkVersion="21" />



<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name=".MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />



<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>



<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>



</manifest>




MainActivity.java

import java.io.File;

import java.io.IOException;







import jxl.Cell;

import jxl.Sheet;

import jxl.Workbook;

import jxl.WorkbookSettings;

import jxl.read.biff.BiffException;

import android.app.Activity;

import android.os.Bundle;

import android.os.Environment;

import android.widget.TextView;



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;

}



}




activity_main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="${relativePackage}.${activityClass}" >



<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world" />



<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_below="@+id/textView2"

android:layout_marginTop="24dp"

android:text="TextView" />



</RelativeLayout>

gilar1360
دوشنبه 13 بهمن 1393, 15:27 عصر
میشه در مورد ش یکم توضیح بدهید ؟(مثلا stock1.xls در کدام مسیر باید قرا بگیره )

pcpsoft
چهارشنبه 15 بهمن 1393, 14:39 عصر
میشه در مورد ش یکم توضیح بدهید ؟(مثلا stock1.xls در کدام مسیر باید قرا بگیره )

دوست عزیز اینیه برنامس که صفحات اکسل رو براتون باز میکنه؟