我想从数据库中存在的数据创建一个单词文件 if($_POST['dashboard'] == "app" { $appchk='checked'; } else {$appchk='';}
if($_POST['dashboard'] == "setup" { $setupchk='checked'; } else {$setupchk='';}
。
为了完成这项工作,我使用的是phpword 0.12.0。
我需要绘制一个表来将数据放入其中。之后我需要从数据库中的表中获取每一行以自动进入新行的单元格。
我可以用
<input type="radio" id="app" value="app" name="dashboard" <?php echo($appchk);?>/>Application
<input type="radio" id="setup" value="setup" name="dashboard" <?php echo($setupchk);?> />Setup
但没有桌子,现在我怎样才能在桌子内的单元格中完成这项工作? 我使用下面的代码,但它不起作用。
You need to use a Theme.AppCompat theme (or descendant) with this activity.
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.paveynganpi.ballonor.ui.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:5933)
at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:305)
at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
at org.robolectric.util.ActivityController.create(ActivityController.java:118)
at org.robolectric.util.ActivityController.create(ActivityController.java:129)
at org.robolectric.util.ActivityController.setup(ActivityController.java:210)
at org.robolectric.Robolectric.setupActivity(Robolectric.java:46)
at com.paveynganpi.ballonor.LoginActivityTest.validateLoginButtonText(LoginActivityTest.java:34)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:245)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:185)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:149)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
com.paveynganpi.ballonor.LoginActivityTest > validateLoginButtonText FAILED
java.lang.IllegalStateException at LoginActivityTest.java:34
1 test completed, 1 failed
答案 0 :(得分:5)
您必须先创建一个单元格对象,然后使用addText
$c1=$table->addCell(2000);
$c1->addText("Cell 1");
$c1->addText("New line");
答案 1 :(得分:1)
正如@Milaza指出的那样,你可以
// define the cell
$cell = $table->addCell(2000);
// add one line
$cell->addText("Cell 1");
// then add another one
$cell->addText("New line");
我认为这很烦人,因为我必须将一行文本分成多行,并且我有很多单元格文本要打破。所以我在PHPWord/src/PhpWord/Element/Cell.php
创建了一个方法(2016-11-08):
/**
* Add multi-line text
*
* @return \PhpOffice\PhpWord\Style\Cell
*/
public function addMultiLineText($text, $fStyle = null, $pStyle = null)
{
// break from line breaks
$strArr = explode('\n', $text);
// add text line together
foreach ($strArr as $v) {
$this->addText($v, $fStyle, $pStyle);
}
return $this;
}
它会从\n
标记中断文本字符串。
因此,当您添加单元格时,可以使用它:
// "$fStyle", "$pStyle" are the old "$fStyle", "$pStyle" you pass to old "addText" method
$table->addCell(2000)->addMultiLineText("Line 1\nLine 2", $fStyle, $pStyle);
输出如下:
Line 1
Line 2
如果您不想修改源代码,我已将其添加到此处。
https://github.com/shrekuu/PHPWord
https://packagist.org/packages/shrekuu/phpword
你可以通过运行:
来安装这个composer require shrekuu/phpword