我正在使用EPPlus。
但是我的文件类型有问题,因为在我工作的地方,我们使用的管理系统仅将@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseApp.initializeApp(this);
setContentView(R.layout.activity_ichild);
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
DocumentReference uidRef = rootRef.collection("RootCollection").document(uid);
POJO pojo = new POJO();
uidRef.set(pojo);
fetch=findViewById(R.id.fetchDocument);
firestore = FirebaseFirestore.getInstance();
upload =findViewById(R.id.uploadText);
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
POJO pojo = new POJO();
pojo.setValue("Hello World");
//below code creates collection, creates a inner doc. and uploads the value (pojo)
firestore.collection("RootCollection").document("MyDoc")
.set(pojo).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
//gets called if upload is successful
Toast.makeText(ichild.this,"Upload is successful", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(ichild.this,"Upload is not successful" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
读取为excel文件。
我尝试将文档另存为SpreadSheet XML 2003
,但没有获得SpreadSheet XML 2003 excel格式
xml
如何使用带有epplus的电子表格xml 2003格式生成Excel?或我可以使用哪个图书馆?
非常感谢!
答案 0 :(得分:1)
我不想使用此解决方案,因为它使用Microsoft.Office.Interop
并且并非所有计算机都安装了excel,但是,我回答了这个问题,因为在我的情况下有人会用到。
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook book = null;
bool status = false;
try
{
var originalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CodigoInteligente" , "Originales" , "Articulos.xls");
var oldFile = new FileInfo(originalPath);
if (!oldFile.Exists)
{
return false;
}
var newPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CodigoInteligente", "Articulos.xls");
var newFile = new FileInfo(newPath);
if (newFile.Exists)
{
if (IsFileLocked(newFile))
{
return false;
}
newFile.Delete();
}
book = xlApp.Workbooks.Open(originalPath);
book.SaveAs(newPath, Microsoft.Office.Interop.Excel.XlFileFormat.xlXMLSpreadsheet);
status = true;
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show("Hubo un error");
Logs.agregarLog(ex);
return false;
}
finally
{
book.Close(false);
xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
}
return status;