SQL 2 Excel - Tutorial PDF Print E-mail

sql2excel_icon_transThis tutorial guides you through the steps of creating your first downloadable Workbook using SQL 2 Excel.  A "Hello Word" for SQL 2 Excel!

This tutorial assumes you have already installed SQL 2 Excel - both the the Module as well as the Component.

  1. In Joomla Administrator, select Component > SQL 2 Excel. This takes you to the SQL 2 Excel control panel."

    sql2excel_controlpanel_thumb

    You can install sample data by clicking on the "Add Sample Data" button. But this tutorial will guide you through the whole process from scratch.

  2. SQL 2 Excel supports Sections and Categories. It is the same concept as Joomla uses to classify articles. First define a Section. Click on "Sections" in the SQL 2 Excel control panel. This will show you the list of defined sections.

    sql2excel_sections_thumb

  3. Click on New in the toolbar. This brings up a form where you can specify the name of your Section. We want to create a section called "Demo" so we fill it in like this:

    sql2excel_tutorial_new_section_thumb

    Note: We can control access to the section with two method. One is by by setting the Access level to Public/Registered/Special. The other is by setting it to Published/Unpublished. When it is Unpublished the section will NOT show up in the SQL 2 Excel module in the frontent. Here we set it to Public access and Published.

    Note 2 : Description is only used for your own notes. Not displayed anywhere at the moment.

    Click on Save to save your Section.



  4. Now you should see the Demo section listed in the list of sections, something like this:

    sql2excel_tutorial_new_section_list_thumb

  5. Next, we need a Category. Click on Categories and then on New. It will bring up a similar form where you enter the Category information. Here I define a Category called "My Category" for this tutorial. Setting it to Public access and making it Published directly. You need to select a section for your category. I select our "Demo" section as the parent of this category.

    sql2excel_tutorial_new_category_edit_thumb

  6. Click on Save The category and you should now see your new category in the list of Categories:

    sql2excel_tutorial_category_list_thumb

  7. Next step is to create Worksheets that we wish to be included in our Excel Workbook. Click on Worksheets and then click on New. It brings up a form where you can define the content of a Worksheet. There are several settings in this form, but it's fairly simple to setup.

    General Settings

    sql2excel_tutorial_ws_general

    The Title is only used in the backend. You can use some descriptive name so that you can identify the worksheet.
    The Sheet Name is the name of the Worksheet in the Excel workbook.
    Include no records : If you set this to Yes then the worksheet will be included even when the query returns zero results. YIf you set it to No then the Worksheet is not even included in teh Workbook when no records are found.
    Message no records : Optional message to show on the Worksheet when no records are found.





    Header

    sql2excel_tutorial_ws_header

    Query

    sql2excel_tutorial_ws_query

    This is the key part of the Worksheet setting. It controls what data you output.

    Column Heading Bg Col : The background color of the column headings.
    Column Heading Text Col : The text color of the column headings.
    Column Heading Text Size : The text size of the column headings.
    Col widths : Column widths. Comma delimited list. In this case we define the width of the first three columns of the worksheet. The rest of the columns will be left at default.
    SQL Query : The SQL query that will be executed for this worksheet. Any valid SQL query can be entered here. Use myPHPadmin, or soem other means to debug and test your queries to make sure they are error free.

    Footer

    sql2excel_tutorial_ws_footer

    Similar to the header. This text shows up at the bottom of the Worksheet, below the data output. Please note the use of a line break to create a space between the data and the footer text.

    Click on Save to store your new Worksheet. It should show up in the list of Worksheets like this:

    sql2excel_tutorial_ws_worksheets_thumb

  8. Finally, we define a workbook. Click on Workbooks and then on New. This brings up a form where you define the workbook properties:

    sql2excel_tutorial_wb_edit_thumb

    We specify a Seaction and a Category for the workbook. This allows us to later display specific Workbooks in the SQL 2 Excel Module. You can copy the module and publish it on different pages. Each module can be configured to show Workbooks only from certain Sections and/or categories.

    At the bottom of this form you can select which Worksheets to include in this Workbook.  Select one or more Workbooks by using the green arrows. You can move the selected Worksheets up or down using the up/down arrows to the right. This controls the sheet order in the Workbook. The Worksheet listed on top will be the first Worksheet. In this case we only include one Worksheet so the order is not an issue.

    We select to publish this Workbook with Public access.

    Click on Save.





  9. The Workbook should now show up in the list of defined Workbooks, like this:

    sql2excel_tutorial_wb_list_thumb


  10. We have now defined our first Workbook. It only has one Worksheet. If you want to add more Worksheets, just define the extra worksheets and then edit the Workbook and include as many Worksheets you need. So how do we now publish these Workbooks? This is where the SQL 2 Excel Module comes in. Make sure you have published the module in Module Manager and that you are displaying it on some page(s).

  11. Go to a page on your site where the SQL 2 Excel Module has been published on. It should now show up and list the Workbook that we defined:

    sql2excel_tutorial_module

    The Articles Workbook shows up. Clicking on the link executes the SQL query that we have defined for the Worksheet and delivers an Excel file directly to the browser. This is what the report looks like in OpenOffice Calc:

    sql2excel_tutorial_openoffice


This concludes the first simple "Hello World" tutorial for SQL 2 Excel.


Still unclear about something?

  • Submit a comment/question below

  • Use our Discussion Forum
Comments (31)add comment

Val said:

0
...
Can you tell me two things:

1. How do I shut off the ability to DOWNLOAD and just leave the view.
2. How do I make the results of a field a hyperlink?

Thank you
Val
 
April 23, 2009
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@Val:

1) Go to SQL 2 Excel Control Panel. Click on "Parameters" button. Set "Show Download Button" = No

2) If a field value starts with http then it will be hyperlinked automatically. For example:

SELECT ID, TITLE, CONCAT('{SERVER_URL}index.php?option=com_content&view=article&id=',ID) AS URL FROM jos_content

See: http://joomla-r-us.com/faq/31-...ion-how-to

If you click on "Add Sample Data" in the SQL 2 Excel Control Panel then you'll get two Worksheets where there's an example on hyperlinks.
 
April 24, 2009
Votes: +3

Mats @ Joomla-R-Us said:

admin
...
@Val:

Another way to do it is to spit out HTML syntax for the link, something like this:

SELECT ID, CONCAT('',TITLE,'') AS Article
FROM jos_content

It will render as a hyperlink in the Preview, but you will see the HTML code in the downloaded spreadsheet.

PS Remove the rel=nofollow. The comment system adds it automatically...
 
April 24, 2009
Votes: +1

Mikey said:

0
...
How do I download the exported file from the back end?
 
October 02, 2009
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
In the backend, create one or more Worksheets. Then create a Workbook, and add your Worksheet(s). You can download the Workbooks in the backend using the "Download" links which are located on the right hand side of the Workbook list in the backend.
 
October 02, 2009
Votes: +0

Mario said:

0
...
How can I use the XLS file "Community_Builder_Users.xml"?

Tks
 
January 25, 2010
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@Mario: Please see the installation instructions for the sample SQL 2 Excel reports: http://joomla-r-us.com/faq/31-...nstruction
 
January 25, 2010
Votes: +0

Derek Brown said:

0
...
Can I configure the output to show as a table ON THE SITE? Instead of having to download?
 
March 13, 2010
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@Derek Brown : SQL 2 Excel Pro comes with a Data Grid Plugin which enables you to embed Worksheets as tables directly into your article content.
 
March 13, 2010
Votes: +0

Frank said:

0
...
With SQL 2 Excel Pro, can I apply a formula to a range of cells? For example, say column c contains a price. I want the user to be able to enter a quantity in column d, and have the result (column c x column d) displayed in column e.

Great product, by the way!
Thanks.
 
March 17, 2010
Votes: +0

Mats @ Jommla-R-Us said:

admin
...
@Frank: You can't apply formulas across ranges - BUT there's no need for that. You can solve that in two ways:

1) Do the math directly in SQL:

SELECT price, quantity, price * quantity as 'Total'
FROM ORDERS

or

2) Embed an Excel Formula in the SQL:

SELECT price, quantity, '=A{ROWID} * B{ROWID}' AS 'Total'
FROM ORDERS

You need to set "Formulas in Columns"=3 in the Worksheet in order to instruct SQL 2 Excel to handle the third column as a formula.

The substitution variable {ROWID} will be automatically replaced with current row number.


Both these methods works in the free version as well as in Pro.

Most people tend to think about Excel formulas for these things - but doing the math/lookup etc in SQL is as easy (or easier IMHO).

-Mats
 
March 17, 2010
Votes: +0

mhpbkk said:

0
...
hi, I hace a couple of date fields that are stored as numbers in the database, how do I convert these back to dates and display them as dates in the excel sheet?
 
March 21, 2010
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@mhpbkk : Depends on what those numbers represent... A not so uncommon way to store dates/time stamps is to use the "UNIX time". The UNIX time is a number which represents the number of seconds passed after Jan 1 1970. If your date's looks something like this : 1269215080

..then it's likely in UNIX time format.

Luckily, MySQL has a built-in function for converting UNIX time to more readable date/time (FROM_UNIXTIME). If your date number column is called "mydate" :

SELECT FROM_UNIXTIME(mydate) as `My Real Date`
FROM mytable

-Mats

 
March 21, 2010
Votes: +0

mhpbkk said:

0
...
thanks! that unix statement seems to work. thanks for the super fast support!

another question, I want to filter the reports based on a user's session. ie. detect who is logged in then filter the report by that persons userID and their session to show the data that applies to them only.

I am using ProjectFork and am trying to use your module to report on tasks, ProjectFork is a Joomla component and so should be linked to the session log for joomla I presume.

could you point me in the right direction how to do this?
 
March 21, 2010
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@mhpbkk : You can use substitution variables in the SQL query.{USER_ID} for example, will be replaced with the current users user id. More info about substitution variables:

http://joomla-r-us.com/faq/31-general/66-sql-2-excel-variable-substitution-how-to

PS! Please use the forum for support questions in the future.
 
March 22, 2010
Votes: +0

Priit said:

0
...
Hi. I have tables, created with JForms. Can I get the reports from those tables in database? What and how to define? Thanks
 
March 29, 2010
Votes: +0

Mats @ Joomla - R - Us said:

admin
...
@Priit: JSforms saves the the form entries in the database. Each form saves the data into a separate database table. The table name is listed in the JSForms backend, for example table name = jos_jforms_9d92d

You can generate a spreadsheet from the data in this table using SQL 2 Excel.

For example:

SELECT *
FROM jos_jforms_9d92d


You will find that the column names are cryptic. You can rename the columns by using aliases, like this:

SELECT h90b7 as 'First Name', h0861 as 'Last Name'
FROM jos_jforms_9d92d


(You have to adjust with your table and column names...)

-Mats
 
March 29, 2010
Votes: +0

Priit said:

0
...
Great! It really works! Thank you, Mats.
By the way - Mats is a traditional Estonian name. Are you from there? smilies/cheesy.gif

Still one more question. I have pictures in those tables. Or actually links to the pictures. But those links appear in excel-report as 10000-digits codes or something... Would be great to have those links also in excel sheet. Is it possible?
 
March 30, 2010
Votes: +0

Mats @ Joomla - R - Us said:

admin
...
@Priit: Regarding the picture links.. How are they stored in the database table? What is the data type of the column? You can use phpMyAdmin etc to check out the table.

PS! No, I'm not Estonian..
 
March 30, 2010
Votes: +0

Priit said:

0
...
In the database table they are usual links, leading to the actual location of the particular picture.
 
March 30, 2010
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@Priit: Not sure why it doesn't come through to the spreadsheet properly. What data type is the column?
 
March 30, 2010
Votes: +0

Priit said:

0
...
Well, I'm too stupid to determine the data type smilies/sad.gif
All the other columns contain a regular text, this column contains links (blue, underlined). If I open the JForms record table, I can simply click the link and the desired picture opens in a new window.
How and where could I find the JForms table column data type?
 
March 30, 2010
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@Priit: Use phpMyAdmin to examine the table structure and which datatype this column has. Also, when using phpMyAdmin, look at the content of this column - how is it stored in the database.
 
March 30, 2010
Votes: +0

Priit said:

0
...
Well, it's embarrassing. I know nothing about phpMyAdmin. I just know, that I'm using MySQL database. How to manage with them together ... that's Chinese to me smilies/sad.gif
 
March 30, 2010
Votes: +0

Priit said:

0
...
smilies/grin.gif First in my life I used phpMyAdmin!! Data type of this column is text
 
March 30, 2010
Votes: +0

Mats @ Joomla-R-Us said:

0
...
@Priit: What does the data look like when you look at it using phpMyAdmin? Do you see the link, or do you see something else?
 
March 30, 2010
Votes: +0

Priit said:

0
...
No link. The same DghYtr745fgfdDGhjkg75dTjjkh.. etc, as it appears in excel sheet. But in JForms, when I look at the records, there is a nice and working link.
 
March 30, 2010
Votes: +0

mats @ Joomla-R-Us said:

admin
...
@Priit : Either the real link is stored in some other table, using this string as a key, or they encode the link in some way in the database. I can't help you with that. Best bet is to look in the source code of the application and figure out how they retrieve the link.

-Mats
 
March 30, 2010
Votes: +0

Priit said:

0
...
OK. Anyway - huge thanks to you.
 
March 30, 2010
Votes: +0

Rudolf said:

0
...
Can i use this?:

SELECT imgid as 'ID obrázku', rating as 'Hodnocení', userid as 'Hlasující', date as 'Datum'
FROM jos_phocagallery_img_votes
SELECT id as 'Obrázek', catid as 'ID kategorie'
FROM jos_phocagallery

I need in one worksheet some field from some another table and make one woorksbook.

Why?

Field imgid (ID photo) is in table jos_phocagallery_img_votes, title (NAME photo) is in the table jos_phocagallery.

Can SQL Query join this information in in workssheet?

Thanks

Rudolf
 
April 27, 2010
Votes: +0

Mats @ Joomla-R-Us said:

admin
...
@Rudolf: You can use any valid SQL query in SQL 2 Excel. The problem is that your query is NOT valid. You can only join two queries like that if the column count AND names are identical. Run the query in phpMyAdmin and you'll see the problem.

You could do something like this:

SELECT imgid as 'ID obrázku', rating as 'Hodnocení', userid as 'Hlasující', date as 'Datum'
FROM jos_phocagallery_img_votes
SELECT id as 'obrázku', catid as 'Hodnocení', '' as 'Hlasující', '' as 'Datum'
FROM jos_phocagallery

The query should be ok, BUT you won't get a separate column heading for the second query - so it will probably look very bad/strange.

You can only add data from one query in the free version of SQL 2 Excel. SQL 2 Excel Pro however, can add results from multiple queries into the worksheet. You can specify the first query as your main query. Then specify the second query as an "Extra Cell" sql query and position the output on the side, or below the first results etc etc. You can add as many "Extra Cell" queries/data that you need in SQL 2 Excel Pro.

-Mats
 
April 27, 2010
Votes: +0

Write comment

security image
Write the displayed characters


busy
 
 
  Design by augs-burg.de & go-vista.de  
 
     
 
   
 

The Joomla!(R) name is used under a limited license from Open Source Matters in the United States and other countries. http://Joomla-R-Us.com is not affiliated with or endorsed by Open Source Matters or the Joomla! Project.