Skip to content

Commit

Permalink
update excel step for macOS
Browse files Browse the repository at this point in the history
expand columns to get correct displayed value instead of compressed cell value
  • Loading branch information
ruthtoh committed Jun 13, 2022
1 parent 7edf034 commit ba65bf7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**Free RPA tool by [AI Singapore](https://aisingapore.org), a government-funded programme to accelerate AI. To start, click the download link below. Take the [free course](https://learn.aisingapore.org/courses/learn-rpa-with-tagui-beginners-course/). Ask any questions at [our Telegram](https://t.me/rpa_chat).**

**[Download v6.109](https://tagui.readthedocs.io/en/latest/setup.html) | [Usage Guide](https://tagui.readthedocs.io/en/latest/index.html) | [Demos](https://github.com/aimakerspace/TagUI-Bricks) | [Samples](https://github.com/kelaberetiv/TagUI/tree/master/flows/samples) | [Slides](https://docs.google.com/presentation/d/1pltAMzr0MZsttgg1w2ORH3ontR6Q51W9/edit?usp=sharing&ouid=115132044557947023533&rtpof=true&sd=true) | [Podcast](https://botnirvana.org/podcast/tagui/) | [Video](https://www.youtube.com/watch?v=C5itbB3sCq0) | [Forum](https://community.aisingapore.org/groups/tagui-rpa/forum/) | [中文](http://www.tagui.com.cn)**
**[Download v6.110](https://tagui.readthedocs.io/en/latest/setup.html) | [Usage Guide](https://tagui.readthedocs.io/en/latest/index.html) | [Demos](https://github.com/aimakerspace/TagUI-Bricks) | [Samples](https://github.com/kelaberetiv/TagUI/tree/master/flows/samples) | [Slides](https://docs.google.com/presentation/d/1pltAMzr0MZsttgg1w2ORH3ontR6Q51W9/edit?usp=sharing&ouid=115132044557947023533&rtpof=true&sd=true) | [Podcast](https://botnirvana.org/podcast/tagui/) | [Video](https://www.youtube.com/watch?v=C5itbB3sCq0) | [Forum](https://community.aisingapore.org/groups/tagui-rpa/forum/) | [中文](http://www.tagui.com.cn)**

---

Expand Down
2 changes: 1 addition & 1 deletion src/tagui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ chrome_command="google-chrome"

if [ -z "$1" ]
then
echo "tagui v6.109: use following options and this syntax to run - ./tagui flow_filename option(s)"
echo "tagui v6.110: use following options and this syntax to run - ./tagui flow_filename option(s)"
echo
echo "tagui live launch TagUI live mode enabled with visual automation for interactive development"
echo "tagui update download and update to latest TagUI version (please backup your version beforehand)"
Expand Down
2 changes: 1 addition & 1 deletion src/tagui.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rem enable windows for loop advanced flow control
setlocal enableextensions enabledelayedexpansion

if "%~1"=="" (
echo tagui v6.109: use following options and this syntax to run - tagui flow_filename option^(s^)
echo tagui v6.110: use following options and this syntax to run - tagui flow_filename option^(s^)
echo.
echo tagui live launch TagUI live mode enabled with visual automation for interactive development
echo tagui update download and update to latest TagUI version ^(please backup your version beforehand^)
Expand Down
6 changes: 6 additions & 0 deletions src/tagui_header.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ var fs = require('fs'); if (!fs.exists(workbook_file))
casper.echo('ERROR - cannot find Excel file ' + workbook_file).exit();
var excel_password_code = ''; if (excel_password != '')
excel_password_code = ' password "' + excel_password.replace(/\"/g, '\\"') + '"';
var column_range = cell_range; if (column_range.indexOf(':') == -1) column_range = cell_range + ':' + cell_range;
var excel_visible_code = 'tell application "System Events"\r\n\t\t' +
'set excel_process to first process whose name is "Microsoft Excel"\r\n\t\t' +
'set visible of excel_process to ' + excel_visible.toString() + '\r\n\tend tell\r\n\t';
Expand All @@ -219,6 +220,11 @@ var excel_steps = 'tell application "Microsoft Excel"\r\n\t' + excel_focus_code
'if not exists sheet "' + sheet_name + '" then\r\n\t\t' +
'do shell script "echo ERROR - cannot find Excel sheet ' + sheet_name + '"\r\n\telse\r\n\t\t' +
'select worksheet "' + sheet_name + '"\r\n\t\t' +
'tell range "' + column_range + '" of active sheet\r\n\t\t\t' +
'repeat with i from 1 to (count columns)\r\n\t\t\t\t' +
'autofit column i\r\n\t\t\t' +
'end repeat\r\n\t\t' +
'end tell\r\n\t\t' +
'set row_count to count of rows of range ("' + cell_range + ' " & get address of used range of active sheet)\r\n\t\t' +
'set col_count to count of columns of range ("' + cell_range + ' " & get address of used range of active sheet)\r\n\t\t' +
'set list_data to {} & string value of range ("' + cell_range + ' " & get address of used range of active sheet) ' +
Expand Down
6 changes: 6 additions & 0 deletions src/test/positive_test.signature
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ var fs = require('fs'); if (!fs.exists(workbook_file))
casper.echo('ERROR - cannot find Excel file ' + workbook_file).exit();
var excel_password_code = ''; if (excel_password != '')
excel_password_code = ' password "' + excel_password.replace(/\"/g, '\\"') + '"';
var column_range = cell_range; if (column_range.indexOf(':') == -1) column_range = cell_range + ':' + cell_range;
var excel_visible_code = 'tell application "System Events"\r\n\t\t' +
'set excel_process to first process whose name is "Microsoft Excel"\r\n\t\t' +
'set visible of excel_process to ' + excel_visible.toString() + '\r\n\tend tell\r\n\t';
Expand All @@ -246,6 +247,11 @@ var excel_steps = 'tell application "Microsoft Excel"\r\n\t' + excel_focus_code
'if not exists sheet "' + sheet_name + '" then\r\n\t\t' +
'do shell script "echo ERROR - cannot find Excel sheet ' + sheet_name + '"\r\n\telse\r\n\t\t' +
'select worksheet "' + sheet_name + '"\r\n\t\t' +
'tell range "' + column_range + '" of active sheet\r\n\t\t\t' +
'repeat with i from 1 to (count columns)\r\n\t\t\t\t' +
'autofit column i\r\n\t\t\t' +
'end repeat\r\n\t\t' +
'end tell\r\n\t\t' +
'set row_count to count of rows of range ("' + cell_range + ' " & get address of used range of active sheet)\r\n\t\t' +
'set col_count to count of columns of range ("' + cell_range + ' " & get address of used range of active sheet)\r\n\t\t' +
'set list_data to {} & string value of range ("' + cell_range + ' " & get address of used range of active sheet) ' +
Expand Down

10 comments on commit ba65bf7

@kensoh
Copy link
Member

@kensoh kensoh commented on ba65bf7 Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruthtoh I haven't tried the code but I can imagine that it expands the columns maybe because unexpanded columns return missing data. Want to add a note to see if u can consider testing some of the tests below to make sure the change doesn't break existing use cases.

#1081 (comment)

@kensoh
Copy link
Member

@kensoh kensoh commented on ba65bf7 Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw nice implementation you made! @ruthtoh

@kensoh
Copy link
Member

@kensoh kensoh commented on ba65bf7 Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also copying @ruthtxh because I'm not sure if your new account gets notifications

@ruthtxh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kensoh
This fix is for the issue flagged up by @lookang as some of his date values get extracted as ####### instead of the date itself.
The root cause is we are taking the displayed value of the cell due to previous issues as discussed here.
So to overcome this while still taking the displayed value, one way is to programmatically expand the cells to autofit.
I've done some tests before pushing the codes but I can test further to see if there's any edge case.

P.S. I pushed the codes from my mac and there's some problem with my github desktop there that keeps connecting to this stray account @ruthtoh. But I'm primarily using my current one!

@kensoh
Copy link
Member

@kensoh kensoh commented on ba65bf7 Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruthtxh oh I see... Do you mean that columns which are too narrow, on Mac Excel it will display as ####### for dates, and thus the extracted data to TagUI will be ####### instead of proper date?

If that's the case, I would think that the adjustment should be done from user's side, by setting the column width correctly so that the displayed value is shown properly, and extracted properly. Otherwise this change will mean that it will modify the user Excel spreadsheet every time, to autofit all columns, since a save is done at the end.

I would think modifying user's column width formatting is a bad idea as that is not something most users want and ask for, and I'll imagine that this change to solve an edge case might give a negative surprise to more users. In general, modifying user's source data is not a good idea. This is my recommendation, but will leave it to you, and perhaps Lawrence to decide on the best approach.

@lookang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried changing on my Mac Windows Excel, the width of the column, but it continues to be reopened in the flow the smaller width despite having save it in Excel in The wider width.

@lookang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I speculate the TagUI 6.110 doesn't modify my data, just make it correctly read by auto adjusting the width of column. I think it is a good change.
I am okay with @ruth changes so far.

@kensoh
Copy link
Member

@kensoh kensoh commented on ba65bf7 Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Lawrence! Gotcha, looks like in absence of other Mac-Excel users feedback, your feedback will be the most accurate and if data or formatting is not corrupted then maybe the right approach is the leave the change there and see how it iterates from there.

@lookang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kensoh thanks again for your awesome tool and your kind understanding.

I think it should a good change to avoid other users getting ###### when the data is actually in numbers like date and time.

@ruthtxh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kensoh @lookang
Ok we will keep a lookout for future feedbacks and iterate from here.

Please # to comment.