How can I set 2D array data to a range? - maatwebsite-excel

I know how to append 2D array to a sheet from a brand new row.
But in my situation, I need to set the 2D array data to the range "B1:G3" below.
2D array data:
[
["2018-01","2018-02","2018-03",....,"2018-12","Total"],
[100,200,300,....,400,2000],
[10,20,33,....,44,300]
]
How it can be done.
By the way, I use maatwebsite/excel 2.1.0
Thank you for any help.

finally I found this in the source code of Laravel Excel.
I can use below:
$sheet->fromArray($2DArrayData, null, 'B1', true, false);
parameters meanning:
/**
* Fill worksheet from values in array
*
* #param array $source Source array
* #param mixed $nullValue Value in source array that stands for blank cell
* #param bool|string $startCell Insert array starting from this cell address as the top left coordinate
* #param boolean $strictNullComparison Apply strict comparison when testing for null values in the array
* #param bool $headingGeneration
* #throws PHPExcel_Exception
* #return LaravelExcelWorksheet
*/
public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false, $headingGeneration = true)
{

Related

How to get the class name inside a child window using pywinauto?

I am trying to automate an app using pywinauto. Here is a problem when I need to locate a specific window.
For example, I want to get the window 'AfxWnd4214', but I can only access to window "AfxWnd42".
| AfxWnd42 - '' (L1044, T410, R1060, B426)
| ['AfxWnd4214', 'V11.82AfxWnd4212']
| child_window(class_name="AfxWnd42")
| AfxWnd42 - '' (L1044, T410, R1060, B426)
| ['AfxWnd4212', 'V11.82AfxWnd4212']
| child_window(class_name="AfxWnd42")
I access it by this code. But it is not specific enough. The sequence of this window may change in the tree.
pywinauto.app.window(class_name = "AfxWnd42", found_index = 0)
When I try this code:
pywinauto.app.window(class_name = "AfxWnd4214", found_index = 0)
It says
pywinauto.findwindows.ElementNotFoundError: {'class_name': 'AfxWnd4214', 'found_index': 0, 'backend': 'win32', 'process': 15404}
Is there any better method to access this window?
Thank you.
There are various search criteria see below; Try using combination of these.
Once I used auto_id and it worked for me.
'''
Find elements based on criteria passed in
Possible values are:
* **class_name** Elements with this window class
* **class_name_re** Elements whose class matches this regular expression
* **parent** Elements that are children of this
* **process** Elements running in this process
* **title** Elements with this text
* **title_re** Elements whose text matches this regular expression
* **top_level_only** Top level elements only (default=True)
* **visible_only** Visible elements only (default=True)
* **enabled_only** Enabled elements only (default=False)
* **best_match** Elements with a title similar to this
* **handle** The handle of the element to return
* **ctrl_index** The index of the child element to return
* **found_index** The index of the filtered out child element to return
* **predicate_func** A user provided hook for a custom element validation
* **active_only** Active elements only (default=False)
* **control_id** Elements with this control id
* **control_type** Elements with this control type (string; for UIAutomation elements)
* **auto_id** Elements with this automation id (for UIAutomation elements)
* **framework_id** Elements with this framework id (for UIAutomation elements)
* **backend** Back-end name to use while searching (default=None means current active backend)
'''

Get actual record of applied record with SuiteScript 2.0

I want to be able to get the shipping/billing address from the applied records when doing something like a Customer Refund.
This is the data I see from an applied record:
amount = {string} 2.56
apply = {string} T
applydate = {string} 11/6/2018
createdfrom = {object} null
doc = {string} 792
due = {string} 2.56
duedate = {object} null
internalid = {string} 792
line = {string} 1
pymt = {object} null
refnum = {string} 63
sys_id = {string} 4917587510484347
sys_parentid = {string} 4917587510342093
total = {string} 2.56
trantype = {string} CustPymt
type = {string} Payment
I initially tried doing this by using the record.Load function. The issue is that this function requires passing in the record type, which isn't given clearly in the apply sublist. I initially tried using the type field, but as you can see above. The proper type is record.Type.CUSTOMER_PAYMENT and here the value just shows as Payment. I switched to using the trantype and having a mapping function, but I don't have all the possible mappings.
My questions are:
Is there an entirely better way of getting the shipping and billing information from the applied record
If the answer to 1 is no, is there a way to get the actual record type from the apply sublist?
If the answer to 2 is no, is there somewhere to have all possible mappings of trantype to record.Type?
You can do a lookup of the address values using search.Type.TRANSACTION like below:
var addressValues = search.lookupFields({
type: search.Type.TRANSACTION,
id: 792,
columns: ['shipaddress', 'billaddress']
});
Address in NetSuite is different record, linked here. So you have to use search, as described above.

Extends Shopware Models

I need to extend Shopware variants models in order to add some custom attributes such as the type of metal,the type of stone a jewel, which is the base article.
These attributes will be used both in backend and frontend.
How can I do that? Thanks
Extending the Shopware core model itself is not possible at all. Depending on what specific model you are trying to extend there would be two different ways for some workaround:
If its the article itself that you want to extend you could use the custom attribute fields as described here: http://community.shopware.com/Anlegen,-Anpassen-und-Ausgabe-von-Artikel-Attributen_detail_1208.html
Another way would be to write a plugin where you create attribute fields by code on plugin install(). This is only possible on entities that do have an attribute table which belongs to the entity itself. For example s_order and s_order_attributes
For the second way create a method in your plugin's Bootstrap.php like the following and call the method in the plugin's install() method:
public function installOrderAttributes()
{
Shopware()->Models()->addAttribute(
's_order_attributes',
'ordermod',
'Random1',
'DECIMAL(12,4)',
false,
0.0000);
Shopware()->Models()->addAttribute(
's_order_attributes',
'ordermod',
'Random2',
'DECIMAL(12,4)',
false,
0.0000);
$metaDataCacheDoctrine = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl();
$metaDataCacheDoctrine->deleteAll();
Shopware()->Models()->generateAttributeModels(array('s_order_attributes'));
}
The addAttribute() function in /engine/Shopware/Components/Model/ModelManager.php has the following signature:
/**
* Shopware helper function to extend an attribute table.
*
* #param string $table Full table name. Example: "s_user_attributes"
* #param string $prefix Column prefix. The prefix and column parameter will be the column name. Example: "swag".
* #param string $column The column name
* #param string $type Full type declaration. Example: "VARCHAR( 5 )" / "DECIMAL( 10, 2 )"
* #param bool $nullable Allow null property
* #param null $default Default value of the column
* #throws \InvalidArgumentException
*/
public function addAttribute($table, $prefix, $column, $type, $nullable = true, $default = null);
Hope this will help.
Kind regards!

When executing FitNesse script, "The instance scriptTableActor. does not exist" error is coming. Can any one explain the meaning of this error?

When executing FitNesse script, "The instance scriptTableActor. does not exist" error is coming. Can any one explain the meaning of this error ?
I have created a fixture in eclipse :
/**
* To enter text or numbers in a text field, add this row to your FitNesse script table:
* <html> <br/> <br/>
* | Enter value xpath | value | in field |fieldXpath |
* <br/> <br/>
* </html>
* tags: setter
* #param fieldXpath the field xpath assigned to the target field
* #param input the characters to be entered
* #return true if text entered successfully
*/
public boolean EnterValueInFieldByXpath(String xpath, String value) {
try {
println "in the EnterValueInFieldByXpath method "
WebElement e = driver.findElement(By.xpath(xpath))
e.clear()
e.sendKeys(value)
return true
} catch (Exception e) {
println "apparently did not find the $xpath Link: ${e}"
return false
}
}
When I use this fixture in FitNesse command such error is coming.
Please guide.
Well there are two things going on here of note. First is that I assume you really are trying to use this as a part of a script table. To that end, script table rows can't be free-standing. So you need a script row. If you are intending a decision table, this isn't the way to do it. See: http://fitnesse.org/FitNesse.UserGuide.SliM.DecisionTable
Second, I'm pretty sure that your row isn't matching the signature of the method. I think it should be:
/**
* To enter text or numbers in a text field, add this row to your FitNesse script table:
* <html> <br/> <br/>
* | Enter value | value | in field |field| by xpath |
* <br/> <br/>
* </html>
* tags: setter
* #param fieldXpath the field xpath assigned to the target field
* #param input the characters to be entered
* #return true if text entered successfully
*/
public boolean EnterValueInFieldByXpath( String value, String xpath) {
try {
println "in the EnterValueInFieldByXpath method "
WebElement e = driver.findElement(By.xpath(xpath))
e.clear()
e.sendKeys(value)
return true
} catch (Exception e) {
println "apparently did not find the $xpath Link: ${e}"
return false
}
}
All of the words in the method name are required in the table use. You were missing some in the example area.
Finally, you had your arguments reversed. Value should have been before xpath, not the other way around.

How can I access array index in Kohana

I am getting the result set in an array. Now I am trying to access the id that is the first index of the array but getting an error. Please let me know how to access the indexes of array.
$email_template = DB::query(Database::SELECT,"select * from mail_settings where id = " .$email['id'])->execute();
When you just run the execute method on a query, you get back a Database_MySQL_Result object.
To return an array instead, use the as_array method like so:
$email_template = DB::query(Database::SELECT,
"select * from mail_settings where id = " .$email['id'])
->execute()->as_array();
Now you will be able to access the resultset as an array.
If all you want/need is the first or current row from the query, you can use the current method which you can read more about in the Kohana_Database_MySQL_Result class:
$email_template = DB::query(Database::SELECT,
"select * from mail_settings where id = " .$email['id'])
->execute()->current();
You are getting a Database_MySQL_Result object, not an array.
This will be correct.
$email_template = DB::query(Database::SELECT,
"select * from mail_settings where id = " .$email['id'])
->execute()->current();

Resources