0

I am creating an app which will view excel files within my app without going to any third party app. So for this i have used jexcel library.

I am able to retrieve data from any Excel file through this library. This is my code.

import android.content.res.AssetManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void order(View v) {
    try {
        AssetManager am = getAssets();
        InputStream is = am.open("Information.xls");
        Workbook wb = Workbook.getWorkbook(is);
        Sheet s = wb.getSheet(0);
        int row = s.getRows();
        int col = s.getColumns();

        String xx = "";
        for (int i = 0; i < row; i++) {
            for (int c = 0; c < col; c++) {
                Cell z = s.getCell(c, i);
                xx = xx + z.getContents();

                xx = xx + "\t\t";
            }

            xx = xx + "\n";
        }

        display(xx);

    } catch (IOException e) {
        e.printStackTrace();
    } catch (BiffException e) {
        e.printStackTrace();
    }

}
public void display(String value)
{
    TextView x=(TextView)findViewById(R.id.textView);
    x.setText(value);
}
}

I am using android studio as my platform –

This is the screenshot of my output.

OutputScreenshot.

I'm only able to view content of Excel file without formatting(e.g. Bold,Italic) and images in my app. I want to display all content of Excel sheet with proper formatting and images. Is there any function through which i can get to know the formatting of the file and set it on my viewer.

0 Answers0