processing underlined/bold/italics text in android - java

I am using jxl api to process contents from an excel file and load them into a json string. I then parse the json string and display contents in various TextViews in my screen. If the excel has any underlined/bold/italics text, then it is not being displayed accordingly in the TextView. Can someone suggest how to make sure any text with underline/bold/italics done in excel gets displayed in textview as well.
Below is the code I am using to process string from excel file
w = Workbook.getWorkbook(inputWorkbook);
Sheet sheet = w.getSheet(0);
Cell storyNameCell = sheet.getCell(1,1);
String Title = storyNameCell.getContents();
//get more cells into Strings
//form the json string from all the String contents above
And this is how I am saving the JSON string above into a local file on android device
String FILENAME = getString(R.string.app_name)+"_"+storyTitle;
FileOutputStream output = openFileOutput(FILENAME,MODE_PRIVATE);
OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8");
writer.write(jObjStoryTitle.toString());
writer.flush();
writer.close();
And finally I am getting any JSON string out of the file for display purpose on user request.
BufferedReader in = new BufferedReader(new InputStreamReader(this.getBaseContext().openFileInput( quizFileName), "UTF-8"));
while ((str = in.readLine()) != null)
fileContent.append(str);
fileString = new String(fileContent);
jObjStoryTitle = new JSONObject(fileString);

I was finally able to get around it. Here is what I did.
-used apache POI api for reading xls file in my android app. Jxl api was not helpful as that does not have capability to recognize any font/style embedded within the part of the text in a cell.
-So using the Apache-POI I then could figure out which part of the text contains underlined characters.
-I then embedded html tags before/after that part
- Then used the Html object to display in Textview as below
myTextView.setText(Html.fromHtml(underlinedText));

Related

Read CSv Data and display total csv data in jsp page

I have CSV page and I want read all columns contains CSV file and display in JSP page
I am using following code:
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
String[] country = line.split(cvsSplitBy);
wordList = Arrays.asList(country);
//System.out.println("data is"+wordList.size());
}
How to display ArrayList in JSP page using struts with display tags.
I am not able to write setter methods of properties because I do not know a CSV file contained how many columns in it as it changes file to file
From what I have understood from your post is that you have the array list of strings and you cannot display it in JSP. Is this what you want?
A quick solution can be to create a new String from that list, and display just a String.

While Writing a .csv file in java tabs are not coming in excel

I want to write a .csv file using some data using JAVA. While I am able to get the CSV file but I am not getting them as TAB deliminator. I want to keep the file type as .csv but the values should be tab deliminated. My code is as follows,
response.setContentType("application/vnd.ms-excel");
PrintWriter out = response.getWriter();
response.setDateHeader("Expires", 0);
StringBuffer fileNameFormat = new StringBuffer();
fileNameFormat.append( "attachment; filename= ReferenceData");
fileNameFormat.append(".csv");
response.setHeader("Content-disposition",fileNameFormat.toString());
StringBuffer totalString =new StringBuffer();
StringBuffer header=new StringBuffer();
header.append("ReferenceId");
header.append("\t");
header.append("TYPE");
header.append("\t");
header.append("VALUE");
header.append("\t");
header.append("ENABLED");
StringBuffer body=new StringBuffer();
if (null != responseBody && responseBody.getResultArray().length > 0) {
DvrReferenceData[] obj=responseBody.getResultArray();
int responseLength = responseBody.getResultArray().length;
for(int i=0;i<responseLength;i++){
DvrReferenceData obj1=obj[i];
body.append(obj1.getRefId());
body.append("\t");
body.append(obj1.getRefType());
body.append("\t");
body.append(obj1.getRefValue());
body.append("\t");
body.append(obj1.getEnabled());
body.append("\n");
}
}
totalString.append(header.toString());
totalString.append("\n");
totalString.append(body.toString());
out.write(totalString.toString());`
Excel is not reading the '\t' when I am giving the file format as .csv, but its happening if i give the file format as .xls enter code here
Put sep=; at the first line of CSV file that will instruct the Excel to split the cell based on semicolon.
Use ; as separator instead of \t for each value when writing into CSV file.
Don't forget to enclose the value inside double quotes.
Here is the sample code:
sep=;
"ReferenceId";"TYPE";"VALUE";"ENABLED"
"1";"T1";"V1","true"
"2";"T2";"V2","true"
"3";"T3";"V3","false"

Saving Information in Hindi

I am using this code to save the data in the file. The data that is being saved in the file is ????????. Please help me with suitable solution.
File gpxfile = new File(activate, "activate.csv");
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(gpxfile),"UTF-8");
writer.write(merchantId);
It works for me. Make sure merchantId contains valid Hindi. For instance:
String str = "मानक हिन्दी";
writer.write(str);

Android java load images from url

I have a question
private final String images[] = {"http://developer.android.com/images/dialog_custom.png", "http://developer.android.com/images/dialog_progress_bar.png"};
how can i change this
to load all of the links from a file from my website?
like a .txt on my site just has like
http://link.com/1.png
http://link.com/2.png
http://link.com/3.png
http://link.com/4.png
http://link.com/5.png
http://link.com/6.png
http://link.com/7.png
http://link.com/8.png
http://link.com/9.png
http://link.com/10.png
so it will just load all those then later on i can add more links without having to update the app
Use a BufferedReader to readLine() to a String and then fetch the image...
Just put the space or "," or "/n" in file then get all data in a string one by one
String reader = "";
String separated ;
BufferedReader buffer = new BufferedReader(new FileReader("YourFileName.txt"));
while ((reader = buffer.readLine()) != null) {
separated = reader.split(" "); or reader.split(","); or reader.split("/n");
//Here at each itration separated will have your single link
}
buffer.close;
Try out the following links:
How to load an ImageView by URL in Android?
http://russenreaktor.wordpress.com/2009/08/11/android-imageloader-load-images-sequencially-in-the-background/
There are plenty of links that provide solutions--enjoy.

Why do I loose new line character when I load text from a java servlet to JTextPane?

I try to load content of a text file that contains some text in multiple lines using java servlet.
When I test servlet in browser it works fine. Text is loaded with new line chars.
But when I load it to a string in my swing application and then use textpane.setText(text); new lines are gone. I tried many solutions I found int the net, but still can't get it right.
Servlet Code:
Reading text from file (simplified):
File file = new File(path);
StringBuilder data = new StringBuilder();
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
while ((line = in.readLine()) != null) {
data.append(line);
data.append("\n");
}
in.close();
Sending text:
PrintWriter out = response.getWriter();
out.write(text));
Is it some platform issue? Servlet was writen and compiled on Linux, but I run it on Windows (on JBoss). Textfiles are also stored on my machine.
Instead of data.append("\n") use
data.append(System.getProperty("line.separator"));

Categories