gpt4 book ai didi

android - 在 jexcelapi 中编码

转载 作者:行者123 更新时间:2023-11-30 04:26:24 26 4
gpt4 key购买 nike

我使用 jexcelapi for android .

我写字符串“Hello jExcelAPI!”,但是当我读的时候我看到了中文符号。

我该如何解决?

提前致谢。

附言也许有帮助:我不知道需要在 ws.setCharacterSet(cs) 中给出什么;

enter image description here

package ru.elvigl.hello;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class HellojExcelAPIActivity extends Activity {

final File file = new File("/sdcard/Folder/File.xls");

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

public void btnExport_Click(View v) throws IOException, RowsExceededException, WriteException {
WorkbookSettings ws = new WorkbookSettings();

//ws.setCharacterSet(cs);
ws.setEncoding("Cp1251");
ws.setExcelDisplayLanguage("RU");
ws.setExcelRegionalSettings("RU");
ws.setLocale(new Locale("ru", "RU"));

WritableWorkbook workbook = Workbook.createWorkbook(file, ws);
WritableSheet sheet = workbook.createSheet("First Sheet", 0);

Label label = new Label(0, 0, "Hello jExcelAPI!");
sheet.addCell(label);

workbook.write();
workbook.close();
}

public void btnImport_Click(View v) throws BiffException, IOException {

WorkbookSettings ws = new WorkbookSettings();

//ws.setCharacterSet(cs);
ws.setEncoding("Cp1251");
ws.setExcelDisplayLanguage("RU");
ws.setExcelRegionalSettings("RU");
ws.setLocale(new Locale("ru", "RU"));

Workbook workbook = Workbook.getWorkbook(file, ws);
Sheet sheet = workbook.getSheet(0);
Cell a1 = sheet.getCell(0,0);
String str = a1.getContents();

TextView tv = (TextView) findViewById(R.id.tvCellValue);
tv.setText(str);
}
}

最佳答案

这是“WorkbookSettings”类的文档:http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/jxl/WorkbookSettings.html似乎方法“setCharacterSet”仅用于读取(导入)电子表格,如果有帮助则不导出。至于中文字符,我认为它们是由于您的语言环境而显示的。我会使用这些常量通过正确的语言和国家/地区构造函数参数正确实例化您的 Locale 对象:http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Locale.html

关于android - 在 jexcelapi 中编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8424607/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com