简体   繁体   English

如何从静态块中的表中写入数据?

[英]How can I write data from a table in a static block?

How can I write data from a table xls in a static block? 如何在静态块中从表xls写入数据? I need a context of activity for this, but I do not understand how to get it. 为此,我需要一个活动的上下文,但是我不知道如何获得它。

I'm using this code in the static block: 我在静态块中使用此代码:

Workbook wb = WorkbookFactory.create(/*there must be a context*/.getAssets().open("table.xls"));

How can I write data from a table xls in a static block? 如何在静态块中从表xls写入数据?

You don't. 你不知道

First, assets are read-only, so you never write to assets. 首先,资产是只读的,因此您永远不会写入资产。

Second, you cannot use a static block for this, as you have no control over what thread will be used to execute that code. 其次,您不能为此使用静态块,因为您无法控制将使用哪个线程来执行该代码。

And, third, you have no Context , and you will need one. 第三,您没有Context ,您将需要一个。 Depending on circumstances, there may not be a Context . 根据具体情况,有可能不是一个Context

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM