Download Excel with pivot table IE appending [1] to file name - excel

Currently I am face this issue.
when I am directly opening from IE with out saving , IE adding [1]/Version to file name
Example: Test.xlsx file in backend but when i am opening the file its renamed to Test[1].xlsx.And this is creating the issue.
Can any one suggest what I am doing wrong here.
//res.setContentType("application/vnd.ms-excel");
//res.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//res.reset();
//res.setHeader("Expires", "0");
myDownloadTask{
//res.setHeader("Cache-Control","must-revalidate,post-check=0, pre-check=0");
//res.setHeader("Pragma", "public");
//res.setContentType("application/force-download");
//res.setHeader("Content-Transfer-Encoding", "binary");
res.setContentType("application/ms-excel; charset=UTF-8");
res.setCharacterEncoding("UTF-8");
fileName=EncodeFileName(fileName);
res.setHeader("Content-Disposition","attachment; filename="+fileName);
}

You have a file with Test.xlsx already on your hard disk, this is why IE rename it to Test[1].xlsx.
I think you can not handle it, you can create a unique file name on the server every time, or gently prompt to user to make sure he does not have a file with same name on his hard disk !

Related

Zip CSV File using Excel VBA

I built a macro that writes a custom csv file to disk. I need to add the option to also save this file in a zipped format. I followed Ron de Bruins excellent article on the matter but face the problem that my zip file is empty.
NewZip (FilePathZip) 'creates an empty zip file
Set objShell = CreateObject("Shell.Application")
objShell.Namespace(FilePathZip).CopyHere FilePathCSV
FilePathZip is the full path to the new zip file I'm creating here. FilePathCSV is the full path to the CSV that was just saved to disk. Interestingly, when I switch out FilePathCSV for any other file that already exists before I run the macro, it works. Apparently, I only face this problem when trying to zip a file that was created during the runtime of the macro.
I already checked if the CSV path is recognized by excel through Dir(FilePathCSV) and made sure that the file is closed after the writing process. I also tried adding timeouts (Wait()). I have no idea what the problem is.
Wrapping FilePathCSV in a Dir() function solved my problem. I'm not sure why though.

Filename of the excel file upon downloading in Codeigniter

Is it possible to set the filename of a excel to a name from database upon downloading ?
Your question is not precise, but I guess, probably you want to set the name of an Excell's file possible to download from your page to the name saved in the database.
In CodeIgniter it's possible to use Download Helper.
First select from the DataBase the name you want to show for users and save it to a variable. For example:
$name.
Load Download Helper:
$this->load->helper('download');
Use function force_download() to serve your Excel file for user with your name from DB:
$data = file_get_contents($excell_file_path); // Read the file's contents
force_download($name, $data);

What .xlsx file format is this?

Using an existing SSIS package, I was trying to import .xlsx files we received from a client. I received the error message:
External table is not in the expected format
These files will open in XL
When I use XL (currently XL2010) to Save As... the file without making any changes:
The new file imports just fine
The new file is 330% the size of the original file
When changing .xlsx to .zip and investigating the contents with WinZip:
The original file only has 4 .xml files and a _rels folder (with 2 .rels files):
The new file has the expected .xlsx contents:
Does anyone know what kind of file this could be?
It would be nice to develop my SSIS package to work with these original files, without having to open and re-save each file. There are only 12 files, so if there are no other options, opening/saving each file is not that big of deal...and I could automate it with VBA going forward.
Thanks for any help anyone can provide,
CTB
There are many Excel file formats.
The file you are trying to import may have another excel format but the extension is changed to .xlsx (it could be edited by someone else) , or it could be created with a different Excel version.
There is a Third-Part application called TridNet File Identifier which is an utility designed to identify file types from their binary signatures. you can use it to specify the real extension of the specified file.
Also after a simple search on External table is not in the expected format this error is thrown when the definition (or version) of the excel files supported in the connection string is different from the file selected. Check the connection string used in the excel connection manager. It might help to identify the version of the file.

What is correct content-type for excel files? without getting any warning

i'm trying to export my datasource from SQLserver to excel 2003 file using this code
Here :
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("Content-Disposition", "attachment;filename=baseline.xls")
the first problem is i have to turn off protected view to open the excel file, the second problem it still give warning massege when i want to open it.
is there any idea how did i wrong ?
the warning sign :
the file you are trying to open, baseline.xls is in a different format than specified by the file extension. verify that the file is not corrupted and is from trusted source before opening the file.
edited : i have tried this line of code to but still have same result
application/vnd.ms-excel

Excel Object in asp.net

I have a serious issue.
I am using excel object for opening the excel file
it works fine i my PC.
when i make application as a website and running the page and uploading it gives the error "'C:\Documents and Settings\Administrator\Desktop\Work\SABRE MSO Mapping Request Template.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted. ".
I think it taking server path...but i want to open client excel file before saving the file to the server.
Plz help.
have you tried server.mappath() method ?? Do you have proper permissions setup to access the folder??
Are you passing complete file path to the excel for opening the file? Please try this:
if (fileUpload.HasFile)
{
string fileName = "PATH_RELATIVE_TO_YOUR_SITE" + "FILE_NAME";
fileUpload.PostedFile.SaveAs(fileName);
//NOW open excel using fileName;
}
also you need write permissions to the path (folder) you are writing file to.

Resources