2

I have a custom query to fetch the details from database (oracle). The results are generating properly as expected. Now i need to download these results either a PDF or an EXCEL file. Any way to achieve this

2

By Views PDF module you can output a View as a PDF.

With this module you can output a view as a PDF document. Each field of the view can be placed on the PDF page directly in the administration interface. Therefore a new display called "PDF" is added.

Since you have your custom query, by Custom query in Views you can alter the results of the View. The print the output of view is PDF using the above module.


UPDATE

Since you created a node and fetch database result via that node you must use Printer, email and PDF versions module

This module allows you to generate the following printer-friendly versions of any node:

  • Printer-friendly version (webpage format) (at www.example.com/print/nid)
  • PDF version (at www.example.com/printpdf/nid)
  • EPUB version (at www.example.com/printepub/nid)
  • Send by email (at www.example.com/printmail/nid)

where nid is the node id of content to render.

so by www.example.com/printpdf/nid you can create a PDF output of the node.

  • Thanks @Drupalist. Custom query is implemented without any views. I Created a node and added a template file with its node id. There i added my custom query to fetch details from database. Do i can download these results.? – drup Sep 10 '15 at 4:49
  • You welcome, I updated the answer – M a m a D Sep 10 '15 at 4:51
  • Is there any way to print entire result without pagination? – drup Sep 10 '15 at 4:55
  • What do you mean? explain a bit more – M a m a D Sep 10 '15 at 4:58
  • I added a custom pagination function to load 10 results per page. Do this modules print the entire results or only 10 results?. – drup Sep 10 '15 at 5:07
1

Using these modules you can do that

views_export_xls

Simple module that allows to export Views data to Excel (xls). Uses php-excel class with UTF8 support.

views

  • You like the default front page view, but you find you want to sort it differently.
  • You like the default taxonomy/term view, but you find you want to sort it differently; for example, alphabetically.
  • You use /tracker, but you want to restrict it to posts of a certain type.
  • You like the idea of the 'article' module, but it doesn't display articles the way you like.
  • You want a way to display a block with the 5 most recent posts of some particular type.
  • You want to provide 'unread forum posts'.
  • You want a monthly archive similar to the typical Movable Type/Wordpress archives that displays a link to the in the form of
    "Month, YYYY (X)" where X is the number of posts that month, and
    displays them in a block. The links lead to a simple list of posts
    for that month.

Views can do a lot more than that, but those are some of the obvious uses of Views.

views_data_export

This module is designed to provide a way to export large amounts of data from views. It provides a display plugin that can rendered progressively in a batch. Style plugins are included that support exporting in the following types:

  • CSV
  • Microsoft XLS
  • Microsoft DOC
  • Basic TXT
  • XML.

Forena

The current version allows you to create reports using SQL from Drupal, or using data stored in XML files.

It comes bundled with a couple of sample reports that will both demonstrate how reports are created, and provide useful information on your existing Drupal site.

Some key features include:

  • Create custom reports from your Drupal database.
  • Create custom reports against PDO supported database (SQLite, MySQL, MS SQL, etc).
  • Create custom reports against any Oracle database.
  • Create charts in SVG format.
  • Export data to CSV, EXCEL or XML versions of reports.
  • Create and edit HTML reports using a simple web UI (includes WYSIWYG editor support).
0

Try out this module. https://www.drupal.org/project/pdf_using_mpdf

API Function : pdf_using_mpdf_api()

      This API function is available to content developers that prefer to generate a pdf file of custom path. The function takes two parameters, first a rendered html content and an optional second parameter, name of the pdf file. E.g: pdf_using_mpdf_api($html) where $html is any html content. 

The module provides API to create pdf for your custom pages, in order to create pdf without pager you can make pager conditional passing a url .parameter or you can have two pages one without pager to create PDF from

0
$link_download = l(t('Download Report'), 'path/to/report/export'); 

function custom_menu(){ 
  $item['path/to/report/export'] = array(
    'page callback' => 'custom_report_export', 
    'title' => 'Data Export',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK, 
  ); 
  return $item;  
}


function custom_report_export() {
  $file = "report_name.xls";
  $table = callback_to_generate_theme_table_output_of_query_result();
  header("Content-type: application/vnd.ms-excel");
  header("Content-Disposition: attachment; filename=$file");
  echo $table;
}
0

Module Forena

You could use the Forena module (disclosure: I'm a co-maintainer of it) as your 1-stop-solution (using only 1 contributed module) to:

  • Build your custom query to fetch the data, whereas these data can be retrieved directly from an external database such as Oracle.

  • Format the look and feel of your results (the report) using xHTML (and/or charts if you'd like).

  • Download the results in any of the typical formats, such as PDF, XLS, CSV, XML, JSON, etc.

To get an idea how its Custom Queries (SQLs) and/or Report Specifications look like, refer to the example in my answer to the question "How to retrieve data directly from a Drupal database.".

The Forena Video demos and tutorials contain quite some links to live demos.

Download options

For any report that you create (using Forena), just add .csv as an extention to the report (output) URL. That contains the CSV equivalent of that report.

As a sample, consider the sample report located at /reports/sample.states (in your own site, one of the samples shipped with Forena). Change the URL to /reports/sample.states.csv (= just add .csv to it) to get the same report in .csv format. By adding such .csv to the URL of the Simple Table of States in the demo site, the result is like so ...

Same technique applies for other supported extensions (export formats), such as:

Moreover, when building a report, you can also specify for which of these Document Types an hyperlink should be made available in the report.

Direct access to data blocks

All data blocks are also accessible directly via their url, provided you have permission to access that block. Here are a few samples of that, for the sample report located at /reports/sample.states:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.