mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
* Fix dispose pattern usage in SaveAsWriterBase * Add SaveAsExcel feature This adds the save as excel function to the backend. To reduce large dependency and run on dotnet core now, this implementation use a raw excel writer (the SaveAsExcelFileStreamWriterHelper.cs) instrad of popular excel library, such as EPPlus or OpenXmlSdk. * Fix can not open the generated excel file in google sheet For the file name inside excel, google uses a case sensitive path while Excel doesn't. This change fix the case, so that the file name matches the one in x1/_rels/workbook.xml.rels * Fix datetime doesn't recognized by google sheet Google doesn't support cell type t="d" with ISO 8601 date. (From stackoverflow thread and testing), thus use the old way of excel datetime, which uses double to present datetime * update to use xmlwriter * Add basic unit tests for SaveAsExcelFileStreamWriterHelper * refactor: simplify the public interface of the SaveAsExcelFileStreamWriterHelper * update private fields names based on the name convention * Add comments to classes of SaveAsExcel feature * clean up SaveAsExcelFileStreamWriterHelper - change SaveAsExcelFileStreamWriterHelper from public to internal - remove the PenddingRowEndTag function from referenceManager - change the SaveAsExcelFileStreamWriterHelper(stream) to default leaveOpen to false to match the normal behavior - change the rowreference to use XmlConvert to convert int to string - rename writeSetting to writerSetting and add private * fix CI test error for SaveAsExcel * remove ExporterException in SaveAsExcel * fix lefe over CSV to Excel in the comments * refactor to be consistent with JsonWriter and remove the comment * remove commented out test The test is too slow to run * fix typo in comment * refactor SaveAsExcel to the coding standard * refactor rewrite the WriteStyle with XmlWriter * Add licence header * reverse mistakenly checked-in changes * fix: left-over CSV in commets * remove duplicate check The check was done in the IncreaseColumnReference, but that check is too late in case of too many columns. All the addCell do the check at the begining now * fix TimeSpan more than 24 hours * fix AddRowMustBeCalledBeforeAddCellException test This is due to remove duplicate call to AssureColumnReference in WriteAndIncreaseColumnReference * fix: TimeSpan will write twice * style: change retun in the switch to break * Add bool format * remove todo in comment This provides extra safeguard in the cost of one memory access when null.
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System;
|
|
using System.IO;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
|
{
|
|
/// <summary>
|
|
/// Factory for creating a reader/writer pair that will read from the temporary buffer file
|
|
/// and output to a Excel file.
|
|
/// </summary>
|
|
public class SaveAsExcelFileStreamFactory : IFileStreamFactory
|
|
{
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Settings for query execution
|
|
/// </summary>
|
|
public QueryExecutionSettings QueryExecutionSettings { get; set; }
|
|
|
|
/// <summary>
|
|
/// Parameters for the save as Excel request
|
|
/// </summary>
|
|
public SaveResultsAsExcelRequestParams SaveRequestParams { get; set; }
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// File names are not meant to be created with this factory.
|
|
/// </summary>
|
|
/// <exception cref="NotImplementedException">Thrown all times</exception>
|
|
[Obsolete]
|
|
public string CreateFile()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a new service buffer reader for reading results back in from the temporary buffer files
|
|
/// </summary>
|
|
/// <param name="fileName">Path to the temp buffer file</param>
|
|
/// <returns>Stream reader</returns>
|
|
public IFileStreamReader GetReader(string fileName)
|
|
{
|
|
return new ServiceBufferFileStreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read), QueryExecutionSettings);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a new Excel writer for writing results to a Excel file
|
|
/// </summary>
|
|
/// <param name="fileName">Path to the Excel output file</param>
|
|
/// <returns>Stream writer</returns>
|
|
public IFileStreamWriter GetWriter(string fileName)
|
|
{
|
|
return new SaveAsExcelFileStreamWriter(new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite), SaveRequestParams);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Safely deletes the file
|
|
/// </summary>
|
|
/// <param name="fileName">Path to the file to delete</param>
|
|
public void DisposeFile(string fileName)
|
|
{
|
|
FileUtilities.SafeFileDelete(fileName);
|
|
}
|
|
}
|
|
}
|