xlwings: copy range and save as an image - xlwings

I have an excel table that I am building using python logic via xlwings. Once calculated, I would like to copy that table (ie its range) and save it as an image (similar format to select range -> copy -> right click -> paste as image ). End goal is to use pptx to include the table in a powerpoint presentation
Is this possible?

I found that the best solution for this is to embed the excel range into the powerpoint presentation.
Copy your excel range, go to the ribbon and click on the triangle under 'Paste', 'Paste Special', 'Paste Link'
This will automatically reflect the changes in the presentation

The way to do this is a bit hacky and there must be a cleaner way but this is what I have found that works for me. The answer below assumes you have data in cells A1 through B3 but you could adjust it for whatever your specific range is.
import xlwings as xw
sht.range('A1:B3').api.CopyPicture(Appearance=2) #2 copies as when it is printed
sht.api.Paste()
pic=sht.pictures[0]
pic.api.Copy()
from PIL import ImageGrab
img = ImageGrab.grabclipboard()
img.save('test.png') #You can obviously save this as whatever filename you want

Related

Power BI parameter for image

I wanted to know if there's a way to have a parameter that holds an image.
The problem: I have 10 PBIX, each one containing over 20 screens. every report has the clients logo. it is an image let's say the client changed his logo, that means I'll need to change the logo 200 times!! (10 PBIX X 20 screens).
Wanted solution: is there a way to hold a parameter that will contain the logo, therefore changing the logo only 10 times (for each PBIX) that will be a HUGE improvement for my time and productivity. sorry for not including pictures this is to keep my client anonymous
Thank you!
Here is how you can achieve your requirement as stated below-
Step-1 create a custom function in Power Query as stated below. The function is taken from Here and you can check this blog for more details if you are interested.
let
BinaryToImage = (BinaryContent as binary) as text =>
let
Base64 = "data:image/jpeg;base64, " & Binary.ToText(BinaryContent, BinaryEncoding.Base64)
in
Base64
in
BinaryToImage
Here below is the image for the custom function-
Step-2 create report wise folder in your local directory and keep your image there. I am considering one folder here, but you can do your own once you get the workaround.
Step-3 Create a data connection for Folder as shown below and point to the folder you kept your logo/image-
And now you will have a table as below with one row as there are one image only. I named the table as PBI_Images.
Here basically Content column holding the Binary data for the image and we have to convert it to Base64 using the Function we created earlier.
Step-4 Now lets Invoke the function in our table. Select the table and do what shown in the below image-
Now you have a new column with data like below-
Step-5 Get back to report by clicking "Close & Apply" button.
Step-6 Download the following App from AppStore-
Step-7 Just add the new downloaded visual to your report and put the newly created column to the "Image URL" field as below-
Step-8 Now add the Image visual to all your report pages and tag the Image URL as stated in step-7.
You are all done now. Just Change the Image in your source file keeping the same name and after that refresh your table (PBI_Images my case) and you will see Image changes everywhere in the report.
Finally, if everything works expected, you can first try will all logos from one single folder. If do not work, go for folder per customer as mentioned earlier.

How to save the result of feature selection in Weka?

I’m trying to use InfoGainAttributeEval in Weka for feature selection, how to save the result? I try to save it but seems like my weka just save my input data, not the result of feature selection.
Welcome to SO. As far as I understand you want to get the ranked values of the attributes. To do this, right click on the "Ranker + InfoGainAttributeEval" statement in the "Result List" section. Select "Save result buffer". You can see the results in programs such as notepad. You can also import it into "Excel" and create it in the chart. I think you selected "Ranker" in the Search Method section. I think it is an image as seen in the figure below.
After selecting and running "InfoGainAttributeEval" and "Ranker" it will give you a "ranked" list (Use full training set). Right click and select "Save Reduced Data" then save. Open the file in notepad as well. Open in Weka too. Select the ones whose Rank value is 0 in Weka and delete them with "Remove". Let those with rank value be left. Now you can get the same result reduced with these features. Save in .arff format. Now you have acquired Reduced data.
If "Save Reduced Data" is not working for you, here is another approach.
Attribute selection can be accomplished in the Preprocess tab.
There is a bar near the top for Filtering the data. Click the
"Choose" button. Under Filters->Supervised->Attribute you will
find AttributeSelection. Select that.
Once it says "AttributeSelection" in the Filter bar, you can click
on the bar to pick a selection method and a search method as well as
set the parameters for those choices.
Once you have made your choices for the feature selection algorithm,
click Apply to the right of the filter bar so that the filter is
actually applied to the data. The data should now have the reduced
feature set. So all you need to do is save it by clicking on the
Save button at the top right.
This should save the reduced data set.

SP 2013 - Quick edit with Managed Meta Data columns, copy and paste from excel

I'm trying to migrate a meta data from an excel spreadsheet to a SP 2013 document library. The columns are managed meta data columns with pre defined terms matching the data in the excel spreadsheet.
However I cannot copy and paste data from excel via Quick Edit in the doucment library without getting the following error "The data returned from the tagging UI was not formatted correctly"
This happens even when I remove all formatting or paste to notepad first.
Are there any simple solutions to this issue?
http://i.imgur.com/1bqpMPA.jpg
Thanks,
Any metadata fields are in fact foreign keys, as it were, to a dynamic, hidden table (or 'list', whatever you want to call it) within SharePoint. To paste a value into a metadata column, you need to know your element's guid (as in, within the term set) and then append that to each metadata element you're pasting in as a <name>|<guid> pair.
Getting the GUID for an element within your term set
Browse to [site-root]/TaxonomyHiddenList/AllItems.aspx and create a new view (or edit the default one) to display the field 'IdForTerm'.
Where you have a term 'apple', your IdForTerm may look like '1288beaf-82e0-4d81-b9de-ad5ad8382938'. Take a note of the guid for each term which appears within your input data.
Edit your input to correctly reference each term
Let's say you're importing your data from an Excel spreadsheet. Or from a CSV. It doesn't really matter. What you need to do is, basically, a find and replace down each managed metadata column, replacing 'term' with 'term|guid'. So our example from earlier, with the apple, would become 'apple|1288beaf-82e0-4d81-b9de-ad5ad8382938'.
Finally, assuming your view is set up in exactly the same order as your input data, you should be able to 'edit list' from within the browser, hit the leftmost side of your first input row (to select the entire row) and CTRL+V all of your data at the same time.
Note there appears to be a limit to the number of entries you can make at the same time. It appears to sit at around 5,000 elements.
Adding on to #rmacd's answer, you can also get the GUID for a given MMS term by first manually entering the value(s) you need in a Quick Edit cell, then copy and paste the same value(s) from SharePoint to Excel. The pasted value will appear with the full term|guid that you need to complete the bulk copy/paste.

cfspreadsheet and modifing tab contents, getting tab exists on update

I am attempting to read a 'named tab' of a spreadsheet into a table, update the values, then save them back to the same tab I am trying to see if its just me or something odd in the spreadsheet functions, pseudo code follows. ( I don't think I am having a coding problem but a cf limitation? specific cold withheld (may add later) )
cfspreadsheet read sheetname query
dump query -- ok
update query and dump -- ok
cfspreadsheet update sheetname query -- fail, already has sheet with sheetname -duh-
(also cfspreadsheet write -- fails)
to get this to work I had resorted to
read tab
modify tab
read workbook -- new var
delete sheet -- new var
saveworkbook -- new var -- disk edition now sans tab..
update workbook add sheet -- using var holding just the modified tab
-- this seems to be horribly resource intensive ... and just plain silly
Forta example seems to be for single sheet workbooks only.
Thanks in advance.
Gary
-- update: Rather than using the tags I switched to functions in script.
No use of query object.
all cf implementation of POI
Cleaner solution follows ... actual code
<cfscript>
// read workbood; set active sheet
sObj = SpreadsheetRead(expectedLocWName);
SpreadsheetSetActiveSheet(sObj, 'Version');
// internal code removed spreadsheet getcellvalue
// update
spreadsheetsetcellvalue(sObj, fileVersionNext, 5, 2 );
var overWriteMe = true;
spreadsheetwrite(sObj, expectedLocWName, overWriteMe);
</cfscript>
The action is just poorly named. Per the docs: update - adds a new sheet to an existing XLS file. You cannot use the uppdate [sic] action to change an existing sheet in a file.
to get this to work I had resorted to
If you do not limit yourself to cfspreadsheet only, you should be able to "update" a sheet by reading in the file, with SpreadsheetRead. Then delete the sheet, and add/recreate it.
Technically you could skip the delete/recreate process and simply modify the existing sheet in place. Just read in the file, set the sheet you want to modify as active, then make your changes. However, depending on the modifications, it is often simpler to just delete the sheet and insert a new one.

Oracle ApexCreate Time field HH:MM

I am having difficulty with a duration field on my form/table.
The users need to indicate in HH:MM how long a meeting took.
What datatype should the column have in the Table. Currently it is TIMESTAMP
How can I make the field have an input mask of 'HH:MM'. What I would like is for the user to be able to type '0130' and the field format it to '01:30' immediately.
Reporting on these times is required so I assume that entering the data as VARCHAR will not help.
Honestly, this is not such an easy subject as people might think it is, and probably more from a user interface point of view than technically.
The easiest way out? The apex datetimepicker. And honestly, if you're new to the technology I'd advise you to use this, especially if you want to steer clear from javascript/jquery initially.
Let's put it this way: the datepicker is fine and works good, but time is really not that fantastic.
Not all that hot right. The value in the input item does not change until you hit 'Close'. The time component seems like a last second sloppy addition honestly. It works, however. (But I'd still set the field to readonly so that a user can not enter text directly.)
Allowing text to be entered means it needs to be validated according to the correct format mask. And format masks differ between those in jQuery (the datepicker) and those in Oracle, and it might be possible that your oracle format mask is not possible in the datepicker, adding even more complexity. There is also no 'live' date validation (nor datetime), there is only the builtin item validation which will check the format mask and which fires on submit.
Anyway, I'd say take a look at it. Set your item to be displayed as a Date Picker, and use the format mask under settings to get the datetime picker:
Now you can push it further of course, though it'll cost some effort. There are several options though.
Personally, when I've implemented date+time I've always split the date from the time in 2 fields. 1 with the date component, and one with the time component, while keeping the item with the original value hidden (so 3 items total). I then use the datepicker on the date item, and use jquery timepicker plugins on the time item. On submit I then add the 2 values together and parse them in a date, and put this value in the original item again (to allow the standard processing to work on items with source set to database column).
One example of a timepicker is here, another one here. They're both not that hard to implement. They have good documentation too. I don't want to dive in the implementation of it here though, I advise you take a look at it first and see how much it scares you. (I'd set up an apex demo but am a bit pressed for time at the moment).
For example, using Trent's (second link) plugin:
put the js file in the apex images directory. I made a folder "/custom" in my case
add the required js files to the page (assuming apex 4.2, put this in javascript file urls)
#IMAGE_PREFIX#libraries/jquery-ui/1.8.22/ui/jquery.ui.slider.js
#IMAGE_PREFIX#custom/jquery-ui-timepicker-addon.js
use onload code such as this to initialize a field
$("#P95_DEPARTURE_TIME").timepicker({hourGrid: 4,minuteGrid: 10});
It'll end up looking as this:
Any further interaction between pickers will need to be handled in javascript code if you want it live. Don't forget server validations.
As for items, my hidden date item has format mask DD-MON-YYYY HH24:MI. Format masks are important, because items are bind variables, and bind variables are varchar2. The value in the html form is also just that, text.
For example, this is on my displayed date item, with a similar setup for the time item:
Then in an after-submit computation I glue the values together again and put them in the m that'll save the value to the database:
:P95_DEPARTURE_DATE_DISP||' '||:P95_DEPARTURE_TIME
This is just a short guide on the setup though, but might be interesting once you're a bit more familiar with the product.
There are also 2 timepicker plugins on apex-plugin, but honestly I don't find them interesting at all when compared to these already existing fine jquery plugins.
Give it some thought and look at it.
If quarters are enough..
item: text field with autocomplete
SELECT ss|| ':' || dd ss_dd
FROM
(SELECT to_char(trunc(sysdate)+(level - 1)/ 24,'HH24')ss
FROM dual CONNECT BY level <= 24),
(SELECT lpad(mod(15 * level, 60), 2, '0') dd
FROM dual CONNECT BY level <= 4)
APEX 4.2: Just to shed some light for any future viewings; now there are loads of Apex plugins for the purpose of picking Date/Time or both returning variations of date time formats as you would required. For e.g. as in your case HH:MM or HH24:MI.
I have personally used TimePicker plugin from http://www.apex-plugin.com which I have no problem in recommending.