-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_xlsx
165 lines (141 loc) · 5.84 KB
/
android_xlsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package materialtest.vivz.slidenerd.activities;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import jp.wasabeef.recyclerview.animators.FlipInTopXAnimator;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import materialtest.vivz.slidenerd.adapters.AdapterRecyclerAnimators;
import materialtest.vivz.slidenerd.materialtest.R;
import materialtest.vivz.slidenerd.views.Util;
import jxl.*;
public class ActivityRecylerAnimators extends ActionBarActivity {
//int containing the duration of the animation run when items are added or removed from the RecyclerView
public static final int ANIMATION_DURATION = 1000;
//edit text letting the user type item name to be added to the recylcerview
private EditText mInput;
//recyclerview showing all items added by the user
private RecyclerView mRecyclerView;
private Toolbar mToolbar;
private AdapterRecyclerAnimators mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_animators);
setupToolbar();
initViews();
writOnFile();
}
private void setupToolbar() {
mToolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
private void initViews() {
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerAnimatedItems);
mAdapter = new AdapterRecyclerAnimators(this);
//set an animator on the RecyclerView that works only when items are added or removed
FlipInTopXAnimator animator = new FlipInTopXAnimator();
animator.setAddDuration(ANIMATION_DURATION);
animator.setRemoveDuration(ANIMATION_DURATION);
mRecyclerView.setItemAnimator(animator);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
}
/**
* Invoked after user hits the button to add an Item to the RecyclerView, check the contents of the EditText,
* if it has valid contents, add the item to the Adapter of the RecyclerView
*
* @param view The Button that was clicked after user types text in the EditText
*/
public void addItem(View view) {
//check if the EditText has valid contents
if (Util.hasValidContents(mInput)) {
// mAdapter.addItem(mInput.getText().toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_activity_recycler_item_animations, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
if (android.R.id.home == id) {
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
public void writOnFile(){
System.out.println("inside beore writting file");
String Fnamexls="testfile" + ".xls";
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard.getAbsolutePath() + "/ARP");
directory.mkdirs();
File file = new File(directory, Fnamexls);
//File file = new File(Environment.getExternalStorageDirectory()+"/"+Fnamexls);
System.out.println(file.getAbsoluteFile());
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook;
try {
int a = 1;
workbook = Workbook.createWorkbook(file, wbSettings);
//workbook.createSheet("Report", 0);
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
Label label = new Label(0, 2, "SECOND");
Label label1 = new Label(0,1,"first");
Label label0 = new Label(0,0,"HEADING");
Label label3 = new Label(1,0,"Heading2");
Label label4 = new Label(1,1,String.valueOf(a));
try {
sheet.addCell(label);
sheet.addCell(label1);
sheet.addCell(label0);
sheet.addCell(label4);
sheet.addCell(label3);
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
workbook.write();
try {
workbook.close();
System.out.println("inside after writting file");
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//createExcel(excelSheet);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}