How to remove a blank sheet: WorkSheet? My code
\moonland\phpexcel\Excel::export([
'isMultipleSheet' => true,
'models' => [
'sheet1' => Order::find()->all(),
], 'columns' => [
'sheet1' => ['id','phone','total'],
],
'headers' => [
'sheet1' => ['column1' => 'id','column2' => 'phone', 'column3' => 'total']
],
]);
The extension you are using is widget that imports or exports data from php to excel or excel to php and it uses PHPSpreadsheet.
You can extend the widget to add your custom function and then call it to remove the worksheet.i will leave that part on to you to extend the widget and then use it.
For a basic example you can follow this
Removing a Worksheet
You can delete a worksheet from a workbook, identified by its index position, using the removeSheetByIndex() method, and to get the index of any worksheet you need to use the getIndex() and getSheetByName() as you wont know the index but the name. See below.
$spreadsheet = new Spreadsheet();
$sheetIndex = $spreadsheet->getIndex(
$spreadsheet->getSheetByName('Worksheet 1')
);
$spreadsheet->removeSheetByIndex($sheetIndex);
If the currently active worksheet is deleted, then the sheet at the previous index position will become the currently active sheet.
Visit here for complete Doc & Guide on Worksheets using PHPSpreadsheet
Related
I am using yii2-formwizard and I want to insert a checkbox as form input field for the field is_legal in a tabular step.
So in fieldConfig array, reading the documentation, I inserted the following code:
'is_legal' => [
'options' => [
'type' => 'checkbox',
],
'labelOptions' => [
'label' => \Yii::t('app', 'Legal Representative'),
],
],
The following image shows the result:
However, when I go the preview step I see the field of the checkbox set as undefined:
In fact, when I try to save the model, the is_legal field is not set.
First Question: where is the problem with the checkbox form field?
Second Question: is there any way to customize the preview step? For example instead of 'Step 5', I would like to write 'Legal Data'.
i created this widget and there are a few things you need to know.
First Answer
The undefined it is showing is not the value but the label of the checkbox, if you look into the getLabel() function in the formwizard.js file it looks into the siblings of the input field for a label and gets its text
let text = $('#' + fieldName).siblings('label').text();
to display on the preview step, and by default Yii2 wraps the input inside the label like
<label><input stype="checkbox"></label>
so you need to use the template option of the checkbox like below
'is_legal' => [
'options' => [
'type' => 'checkbox',
'template' => '{input}{beginLabel}{labelTitle}{endLabel}{error}{hint}',
],
'labelOptions' => [
'label' => \Yii::t('app', 'Legal Representative'),
],
],
Second Answer
No, currently the widget does not support the custom title for the Preview step sections, but i think I can add the support for providing the title of the headings as it makes sense too, if that sorts your problem.
Update
Ignore the Second Answer given above i just pushed the updates to the live branch you can now use the previewHeading option in the step settings. Update your composer by running composer update to update to the latest version and clear cache using CTRL+F5.
See the following sample code how to use previewHeading option
use buttflattery\formwizard\FormWizard;
echo FormWizard::widget([
'enablePreview'=>true,
'steps'=>[
[
'model'=>$user,
'title'=>'My Shoots',
'previewHeading'=>'My Heading Step 1',
'description'=>'Add your shoots',
'formInfoText'=>'Fill all fields'
],
[
'model'=> $profile,
'title'=>'My Shoots',
'previewHeading'=>'My Heading Step 2',
'description'=>'Add your shoots',
'formInfoText'=>'Fill all fields'
],
]
]);
I have two actions with parameters. I have written two url rules, but only one works at a time. I don't know the issue. These are my acions,
Index action in Site Controller and other one is index action in Product Controller
public function actionIndex($language = null) {
/* some codes */
}
public function actionIndex($id= null) {
/* some codes */
}
'rules' => [
'<language>' => 'site/index',
'<id>' => 'product/index',
]
The above are my url rules.But only the first rule is working. What is the issue?
Your rules are ambiguous. '<language>' pattern will match every URL, so second rule will never be reached. You should either create different URL structure for these two rules:
'rules' => [
'<language>' => 'site/index',
'id/<id>' => 'product/index',
],
Or use different patters (only literal languages and numerical IDs):
'rules' => [
'<language:[a-z]+>' => 'site/index',
'<id:\d+>' => 'product/index',
],
I have a tree node in my form. I am using kartik-v's Tree Manager.
This is my view code:
echo TreeViewInput::widget([
'query' => Tree::find()->addOrderBy('root, lft'),
'headingOptions' => ['label' => 'Set Permission'],
'name' => 'name',
'value' => '1,2,3',
'asDropdown' => false,
'multiple' => true,
'fontAwesome' => true,
'rootOptions' => [
'label' => '<i class="fa fa-tree"></i>',
'class' => 'text-success'
]);
But, in this I have to follow the same table structure as mentioned in the widget. I have some extra fields and more permissions. So it is a bit complicated to use the same structure.
Is it possible to pass the value in an array directly to this widget? If possible let me know the array format.
Now I am stuck with this tree node implementation.
You can do this by doing some tricks, or by using another way:
1) you can add a condition to your query like this:
Tree::find()->andWhere(['not in','id',[2,3,4]])->addOrderBy('root, lft'),
by this solution you can ignore unwanted rows like you send data direct in array...
2) you can use another solution by using js lib/plugin direct like jsTree, in this case you can create and pass custom array direct...look at this example: jsTree Example
the \kartik\grid\EditableColumn widget has a parameter called ajaxSettings where you may override the parameters passed with the ajax request to the server. What i want to do is to dynamically pass the selected rows ids together with the value coming from the popover to the server. I manage to do that passing static parameter coming from a php array in compile time like so
Editable::widget(['name' => 'publishDate', 'ajaxSettings' => ['ids' => [1,2,3]]])
but It seems that i cannot use a jquery selector there to grab the ids of the selected columns like so
Editable::widget([
'name' => 'publishDate',
'ajaxSettings' => [
'ids' => '$("#books-grid").yiiGridView("getSelectedRows")'
]
])
Maybe you want to try creating a variable outside the Editable::widget([ like this:
var arrayIds = $("#books-grid").yiiGridView("getSelectedRows");
And then assign it to the widget:
Editable::widget([
'name' => 'publishDate',
'ajaxSettings' => [
'ids' => arrayIds
]
])
Hope this helps,
Leo.
I am working on an automated form submit script. It is logging in to a vendor's website and populating the fields of a form. When trying to submit, the desired result would be a ticket number displayed, which is acknowledging the form is submitted and the request is processed by their helpdesk.
However the form is not submitted correctly (no acknowledgement is displayed) and I suspect that it is caused by one of the inputs which is a SELECT.
Here is the code I use to set this field:
$forms[3]->value('ProductList','-2');
This has no effect on the the prepared form unfortunately, dumping $forms[3], i see this:
[...]
bless({
'onchange' => ' checkKC(document.all.ProductList, \'~0\'); prodExpand();',
'current' => 1,
'menu' => [
{
'seen' => 1,
'value' => '~0',
'name' => '<Please select>'
},
{
'seen' => 1,
'value' => '-2',
'name' => 'Product not found.... Search more'
},
{
'value' => '-1',
'name' => '------------------------------------'
},
{
'value' => 'Product1',
'name' => 'Product 1 Name'
}
],
'name' => 'ProductList',
'id' => 'ProductList',
'idx' => 1,
'type' => 'option'
}, 'HTML::Form::ListInput' ),
[...]
Am I using the right method of $forms[3]? (it was created by HTML::Form->parse($pageresult) btw) Or is there any other method I should try? I can't find any documentation for HTML::Form::ListInput
Thanks for any advice
Consider using WWW::Mechanize for form processing that takes more than one step. That way you can include the login process in your script along with going to the form and of course getting the result.
Or if you need to work with JavaScript, then use WWW::Mechanize::Firefox.