I want to display an excel sheet in my android application. I have googled and yet cannot find a starting tip to render an excel file using android components. If anybody knows any thing please give me some valuable hint.
You can use Apache POI or Java Excel API.
In android jxl.jar is use for create excel sheet. and it is available at here
and you can create excel sheet by using following code.
File root = Environment.getExternalStorageDirectory();
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append("NAME");
Try GridView.
Related
This code works:
string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "File.text");
File.ReadAllText(file);
Pretty straight-forward, but when I display the variable "file" using a Pizel 5 simulator I get a weird path: /data/user/0/com.companyname.aikidohours/files/.local/share/File.text. I can write new data to the file and read from it. but I now want to read from an existing file and I can't figure out where to put the file. Can someone tell where to put a text file full of basic information that I need to read from in Xamarin for adnroid?
Thanks
Todd
If you want to deploy that file with your application, you can add it to the 'Assets' folder inside your_project_name.Android project.
WARNING!!! File put in this folder are READONLY!
In case this is ok for you,this is the code to access the file:
using Xamarin.Essentials;
using (var reader = new StreamReader(await FileSystem.OpenAppPackageFileAsync("file_path")))
{
string content = reader.ReadToEnd();
}
I am trying to create a PDF file by inserting some text into it with a proper structure in Android.
Document doc = new Document();
PdfWriter.getInstance(doc, new FileOutputStream("urgentz.pdf"));
doc.open();
Image image = Image.getInstance ("urgentzImageahslkdhaosd.jpg");
doc.add(new Paragraph("Your text blah bleh"));
doc.add(image);
doc.close();
The above code does not work.
Without seeing stacktrace I can only guess what's wrong. You might find these questions useful:
How to create PDFs in an Android app?
how to Generate Pdf File with Image in android?
Some ideas:
Check File paths. You have specified only filenames to pdf and image without any paths. Use something like /mnt/sdcard/<YourFolderHere>/somefile.pdf and make sure you have defined android.permission.WRITE_EXTERNAL_STORAGE in AndroidManifest.xml
Use droidText instead of iText
Try another PDF Writer library http://coderesearchlabs.com/androidpdfwriter/
The file i want to open is located in the file:
/data/data/MY_PACKAGE/files/samplefile.txt
I have pulled the file from ddms and the desired content is in it
I just want to get the text file in order to parse it..
I tried the following:
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File xmlFile = new File(sdcard,"samplefile.txt");
but no joy...
Thanks in advance!!
Use getFilesDir(), not Environment.getExternalStorageDirectory(), to get at the root of internal storage, where your file resides.
In order to open a file stored within your applications private directory you must use openFileInput(String fileName). This will return a FileInputStream that you can then work with.
So in my Eclipse android project I have a pdf file that I'd like to open, I looked up the standard address on the android developer's page and I came up with this pointer:
File file = new File("Android/data/com.alex.testing.app/res/raw/jazz.pdf");
where jazz.pdf is situated in res->raw in my eclipse project,
and com.alex.testing is my package name.
Still, when I try if(file.exists()) , the function returns false (on the emulator it goes to an else I've set up to display an error message)...
Sorry for the newbie question, but I'm really stuck with this :(.
put the file in assets folder and pick the file from there
Now use Context.getAssets().open("jazz.pdf") and pass the resulting InputStream into PDf parser library
Ok, to access resources from current application you can use something like,
Uri path = Uri.parse("android.resource://<you package>/raw/<your_file.pdf>");
OR
Uri path = Uri.parse("android.resource://" + getPackageName() + "/" R.raw.<your_file.pdf>);
But I have a doubt if you are trying to use this pdf file in your application then its OK, but If you want to view this file using any third party application then I think you can't do it.
Because external application can't access application's package resources file.
So better way it to put this file in /asset directory then copy it to any public access area then view that file from that path.
//if your are stored in SDcard your location would be
"data/data/com.alex.testing/res/raw/jazz.pdf"
//you read resources from raw folder thru the below code
InputStream inputStream = getResources().openRawResource(R.raw.jazz);
byte[] reader = new byte[inputStream.available()];
I want to read text file, that was written by other my app. It's saved ad "Android/data/MyPackageName/files/"
I use this code:
File file = new File("//Android//data//MyPackageName//files//", "filename.txt");
FileInputStream is = new FileInputStream(file);
but i get exception "no such file or directory"
I am sure that solution is pretty simple, but i can't find it yet.
Thank you for your help!
I don't think it is right to use the double backslash "//", one is enough. Also, the path should be "/mnt/sdcard/Android/data....". I am not sure the "/mnt/sdcard" is applicable on every device, so my suggestion is to use Environment.getExternalStorageDirectory to get the root dir on sd card.