Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 790983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:45:46+00:00 2026-05-14T21:45:46+00:00

I am currently exporting data from php to excel using the code as below:

  • 0

I am currently exporting data from php to excel using the code as below:

include("dbconnect.php");

$query = $_POST['query'];
$result = odbc_exec($conn,$query);

$count = odbc_num_fields($result);
//Define Variable For ODBC
$data = "";
//Field Name Data
for ($i = 1; $i <= $count; $i++)
    {
        $data .= odbc_field_name($result, $i)."t";
    }

$data .= "n";    
//Row Data
while(odbc_fetch_row($result))
    {
        for ($j = 1; $j <= $count; $j++)
            {
                $data .= odbc_result($result, $j)."t";
            }
        $data .= "n";
    }

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=ExcelFile.xls;");
header("Pragma: no-cache");
header("Expires: 0");
echo $data;   
odbc_close($conn);

This all works fine, but the generated excel file has a sheetname of: “.xls]ExcelFile(1)” , and when you try to rename the sheet it causes an error in excel (unless you save the file first).

How can I define the sheetname in my php file?

Thanks in advance!

Have a nice weekend:-)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:45:46+00:00Added an answer on May 14, 2026 at 9:45 pm

    By changing the

    header("Content-type: application/octet-stream");
    

    To

    header("Content-type: application/vnd-ms-excel");
    

    It is downloading without any errors and i am able to save that. the worksheet name is same as excel name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently exporting data from an excel import using excel interop. I've been
Hi I am exporting my mysql data in excel format currently I have 14k+
I currently have a sproc that is exporting data to a csv file using
I have implement functionality for exporting data from gridview to excel sheet in .net
I am currently exporting data from App Engine (to csv files) so that a
I am currently using CURL via a php script running as daily cron to
I need to make an excel file which would fetch data from connection to
I'm currently exporting a database table with huge data (100000+ records) into an xml
I'm exporting a some data from a survey to CSV for use by another
I am currently working on a php/javascript project which retrieves information from a database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.