我正在将mssql查询导出到excel文件,该文件的前两行作为标题。第一行(标题)是一个跨越A1:K1的单元格。第二行(标题)有11个单元格,跨越A2:K2。我想有一个openrowset来更改标题,第二个openrowset来填充excel文件。
这不起作用:
EXEC('INSERT INTO OPENROWSET(''' + @provider + ''',''' + @ExcelString + ''',''SELECT Top 1 * FROM [Sheet1$]'')
SELECT Top 1 [Customer] FROM [ORDER SUMMERY] WHERE [Order #] = ''' + @OrderNumber + ''' AND (Status = ''C'' OR Status = ''I'')')
这是第二部分,它确实有效:
EXEC('INSERT INTO OPENROWSET(''' + @provider + ''',''' + @ExcelString + ''',''SELECT * FROM [Sheet1$A3:K3]'')
SELECT [ITEMNUMBER],[CustomerSKU],[ITEM_DESCRIPTION],[CASEPACK],[Total Qty],[Case Price],[CASEPACK]*[Total Qty],[Total Qty]*[Case Price],[Unit Price],[PreTicketInfo],[Quote #] FROM [ORDER SUMMERY] WHERE [Order #] = ''' + @OrderNumber + ''' AND (Status = ''C'' OR Status = ''I'')')
谢谢!
答案 0 :(得分:0)
EXEC('INSERT INTO OPENROWSET(''' + @provider + ''',''' + @ExcelString + ''',''SELECT Top 1 * FROM [Sheet1$A1]'')
SELECT Top 1 [Customer] FROM [ORDER SUMMERY] WHERE [Order #] = ''' + @OrderNumber + ''' AND (Status = ''C'' OR Status = ''I'')')
试试这个。 Excel保存合并单元格区域左上角的合并单元格的值,因此在拉取值数据时,跨越A1:K1的合并法术将以编程方式称为单元格A1