-1

There is a requirement in my project to automate some SQL queries and i did but after that one user came and ask that we do not want 2 separate .csv file we want 1 .csv file with multiple sheets

For eg. suppose there 2 .csv files "Text1.csv" and "Text2.csv" and we are sending this to users but they are coming back asking to do it like a "Text.csv" file with "sheet1" and "sheet2" sheets.

I have been using below

@echo off
cls
@echo *****************************Reports****************************
@echo.

sqlcmd -h-1 -S database -E -i "loc.sql" -o "loc2.csv"

sqlcmd -h-1 -S database -E -i "loc1.sql" -o "loc2.csv"

@echo Report is generated
@echo.

Note: I can not use any 3rd party tool like java or jscripts, neither i can use Visual studio for VBS, i have only option with batch cmd file

PS. if there is another kind of script that can write as a batch file without any need of 3rd party tool that will be great

Stephan
  • 53,940
  • 10
  • 58
  • 91
Rishabh Bhargav
  • 35
  • 1
  • 11

1 Answers1

0

This isn't possible as the CSV format doesn't support multiple sheets (presuming that you are trying to view the file in excel).

The most you can do with a batch script is append one file onto another

copy File1+File2 NewFile
zglin
  • 2,891
  • 2
  • 15
  • 26
  • Thanks for responding @zhqiat.... but this way.. i can not resolve the query of user, we were sending excel(.xlsx) files before this and in that we were putting data manually in tabs. so now if i am automating they want the same and exact, the way it was – Rishabh Bhargav Sep 01 '16 at 18:16
  • Or is there any way that i can create a excel file(.xls or .xlsx) through batch command? – Rishabh Bhargav Sep 01 '16 at 18:18
  • 1
    a `csv` file is a textfile only. There are no tabs. If you want tabs, you can't use `csv` files. You have to use "real" Excel files `xls(x)`. But you can't process Excel files with batch, you have to use some other language (powershell might do the trick) – Stephan Sep 01 '16 at 18:21
  • +1 to @Stephan XLSX files have to be created via a more high level language. You can try to use a batch script to call a vba script which creates your excel file. – zglin Sep 01 '16 at 18:22
  • Vbscript and Powershell can both modify excel files. – Squashman Sep 01 '16 at 18:53
  • The sqlcmd can output as XML. Excel can read the XML file just like it is an Excel file. That is what we do here where I work but we use SAS to create the XML. Not sure how you would create multiple sheets with your sqlcmd. – Squashman Sep 01 '16 at 18:58
  • Thanks for that @stephan .... i think i will go with powershell.... just 1 ques in mind.... can we call powershell script through a batch file?? – Rishabh Bhargav Sep 01 '16 at 21:22