How to render tables in Slack - slack-api

I have a slack application that responds with formatted data in mrkdwn but it would be nice to have the information presented in table form like so
Am trying to implement this but cant quite find how to format this message. The only close solution i have is taking a screen grab of the table and sending it instead but that affects the applications response time. Any help would be appreciated thanks

Slack has no built-in support to render tables in messages.
Your workaround options are:
Draw table with chars in the message using a monospace font (Example)
Draw table with chars and upload as plain text snippet with files.upload
Render table as image and attach to a message or upload as image

I used tabluate in python for create a formatted table from pandas dataframe then I posted the table using slack python client's chat_postMessage method using below technique:
client.chat_postMessage(channel="#dummy-channel",text="```\n" + table + "\n```")
Note "```\n" + table + "```\n" is being used to convert table into code block just like we as users do in slack.

First convert to markdown
markdown_table = df.to_markdown()
Prepare data to send to the webhook url via requests.post
slack_data = {"text":"```\n" + markdown_table + "\n```"}

If your data is simple with up to one text column and some number columns, try this. Be creative or die!
Landing page report (views, buys)
1754 17 https://example.com/variant-a
1834 23 https://example.com/variant-b

Related

Print Core Data Results To New Controller and Send To Email

* Edit * So my last question is, how to I get the data shown to be sent in email. I have done much HTML email in my other apps, but am confused as to what I am asking to look for / reference from core data and the proper formatting of code...
Using core date to populate UITable... all good... works as planned... (see pic 1) question... how can I get the result to format and and perhaps display as a UILabel on another controller similar to other results (see pic 2)... and then part two of my question... How can I get that result to print nicely in an email... I have used other code (not from coredata) to print and all works nicely together... I am stumped by the coredata portion...
In the result, you can see the math works out from core data, just don't know how to capture what the user typed in from core data (see pic 3)
Any help greatly appreciated...
EDIT (Clarification)...
I guess I want to show what the user has input into a new view controller and have it displayed in a readable format... (see image)...
Maybe my question is more... how to I PASS the data THAT THE USER CREATED from the Core Data Table Model to a new view controller and display the incoming text as a UILabel? (Can the new view controller be updated automatically? The user may add a new row, delete a row, change the hourly rate on an existing row, change a label etc. etc.. Once that is solved, I'd like to know how to send the results in an email so the end user can print for hard copy documentation... I have this scenario working in other apps, but they do not use core data...

Excel to pdf conversion in rails4 with libreoffice

In a rails 4 application, how can I convert an excel spreadsheet file into pdf.
When I am trying to implement Excel to pdf the contents are listed in different pages if excel column size is large.
How to generate the pdf without moving data to next pages in pdf.
Please help,
Thanks
So you basically have two options you can either implement this yourself and use a CSV gem/library (default CSV, faster CSV, or smarter CSV) assuming that by "excel" a CSV is acceptable. If a CSV is not acceptible you can use the axlsx gem instead. Then for pdf conversion you can use something like prawn. If you decide to build this yourself follow these steps.
Create a controller that will handle Reports, I suggest using the rails g controller report upload generate_table show generate_pdf generator to create a controller and a view for the upload process
Create a file upload form in the upload view.
On submit you will send the file to the generate action processing with one of the CSV or excel gems
Once processed your end product should be an array or hash (as an instance variable) and you can send that to the show action
In the show view you will iterate of that hash/array and incapsulate the contents in a html table.
On the show view you should have a button that will send that same hash/array to the generate_pdf controller action where you will use prawn to create a pdf, you can use something like send_data to the send the completed pdf file back to the user.
This is roughly how you could go about it less the low level details. Now if you wanted to use an out of the box solution you could use something like Ruport. Ruport will handle most of the heavy lifting for you the only thing is you need to have your models and associations set up to use it the way it is designed, and that may not be an option for you.

can I force Outlook 2007 rule to print first page only?

I have set up a rule to quite simply print out an email when received from a certain address (Amazon sales) - The idea being that as orders come in, they are auto printed and waiting to be packed.
However the amazon emails require 2 pages.
under the Rules menu in Outlook, the option is simply "Print" but no further print preferences are available.
Is there a way to get it to print the first page only? a script possibly?
No, Outlook Object Model does not porvide any fine controls over the print functionality. As a workaround, you can export the message as a DOC file (MailItem.saveAs), then programmatically load it in Word and use the Word Obejct Model to print it.

How do I pull text from google document to display on my site?

I have a user who wants to update the text on their website using a google document. Is it possible?
I haven't looked into whether it's possible with an API, but I do know that it's possible to load the page and parse the contents quite easily.
Here is a (rather pointless) snippet from when I parsed a Google document using C# -
contents = title = browser.ResponseData;
contents = contents.Substring(contents.IndexOf(">DOCS_mutations") + 20);
contents = contents.Substring(0, contents.IndexOf("\"}") + 1);
contents = contents.Substring(contents.IndexOf("\"s\":"));
contents = contents.Substring(contents.IndexOf(":") + 1);
contents = contents.Substring(1, contents.Length - 2);
title = title.Substring(title.IndexOf("/><script type=\"text/javascript\">"));
title = title.Substring(title.IndexOf("config, '") + 9);
title = title.Substring(0, title.IndexOf("'"));
The above snippet is grabbing the content of the document from the HTML by parsing the following region (where foo was the contents of my document) -
DOCS_mutations = [{"ty":"is","ibi":1,"s":"foo"},
This information is a mere example of how possible it would be to do this.
It is important to note that some characters are replaced with others so that they do not interfere with the HTML. For example, the content of
foo " / \ <
is replaced with
foo \" / \ \u003C
I would highly recommend that you consider thinking of an alternative that would satisfy your client, as such a method of parsing another page in order to update another feels very unnecessary.
Assuming you're using PHP, if you really need to go through with this, then I would recommend using cURL or file_get_contents() to download the document on your server.
I should note that you must consider the efficiency of your ideas, as you certainly don't want to be downloading the latest document from Google Docs every time someone wishes to view one of your pages. I would recommend invoking a re-download upon the request/instruction of a site administrator. Also note that the Google Docs update the server-side version regularly (whilst you're modifying the document). This is important to note, as this would make it possible for your server to download an unfinished document, should you not take this into consideration.
Finally, As an alternative to using Google Docs, I wish to suggest creating an administration control panel for your client to use. Ask him what it is about Google Docs that makes him wish to use it in such a way, and then implement the features that would make your own editor an acceptable alternative for Google Docs.
Let me know if you need further clarification, or if you desire some example code.

Creating a pdf invoice in rails/ruby

I want to create an invoice in PDF format using rails/ruby.
So company header and the top, client information, and then line items with pricing and then a total at the bottom etc.
What do you guys advise?
Is it tricky to get the formatting correct so it prints out correctly?
I recommend a gem called prawn:
http://prawn.majesticseacreature.com/
I've used it before and liked the results.
There is this great alternative oo:
http://railscasts.com/episodes/220-pdfkit

Resources