August 2, 2022 at 10:48 am
I need to append data to excel file already exist from table students on SQL Server .
Excel file already Created on D:\ExportExcel\dbo.students.xlsx with student IDs 1 and 2.
Table Insert Commands:
INSERT [dbo].[students] ([StudentId], [Name]) VALUES (3, N'Sayed')
INSERT [dbo].[students] ([StudentId], [Name]) VALUES (4, N'Michel')
Python script used
DECLARE @PythonScript NVARCHAR(MAX) = N''
declare @SQL NVARCHAR(MAX) = N'select studentid,Name from dbo.students;'
declare @ExportPath varchar(max)='D:\ExportExcel\'
declare @TableName varchar(max)='dbo.students'
declare @FullFilePath varchar(max) = concat(@ExportPath,@TableName+'.xlsx')
SET @PythonScript = N'
FullFilePath = ExcelFilePath+TableName+".xlsx"
InputDataSet.to_excel(FullFilePath,sheet_name=TableName.split(".")[-1],index=False)'
EXEC sp_execute_external_script
@language = N'Python'
,@script = @PythonScript
,@input_data_1 = @SQL
,@params = N'@ExcelFilePath NVARCHAR(MAX), @TableName NVARCHAR(200)'
,@ExcelFilePath = @ExportPath -- file path where Excel files are placed
,@TableName = @TableName
When use Python script explain it will not append data to Excel file from table students. Meaning it will not add student IDs 3 and 4 .
So How to append data from table students to excel file using Python script?
Expected result to file after append
August 2, 2022 at 12:09 pm
What happens when you run this? Does the existing data in Excel get overwritten, or does the Excel file remain unchanged?
August 2, 2022 at 4:17 pm
it remain without change
meaning after apply script
nothing change
but not append to existing file
an nothing change
August 3, 2022 at 9:40 am
If you remove the existing data from the Excel file, does the new data get written to the file?
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy