Export excel sheer
This commit is contained in:
@@ -112,10 +112,10 @@ namespace WebAPI.Controllers
|
||||
public IActionResult ExportToGoogleSheet(Guid id)
|
||||
{
|
||||
Layer layer = db.Layers
|
||||
.Include(x => x.Records)
|
||||
.Include(x => x.Records!.OrderByDescending(x => x.Code))
|
||||
.Where(x => x.Id == id && !x.IsDeleted).First();
|
||||
|
||||
var export = new googleSheetExport(googleDriveHelper, googleSheetValues);
|
||||
var export = new googleSheetExport(googleDriveHelper, googleSheetValues, configuration);
|
||||
export.export(layer);
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Google.Apis.Drive.v3.Data;
|
||||
using System.Globalization;
|
||||
using Google.Apis.Drive.v3.Data;
|
||||
using Google.Apis.Sheets.v4;
|
||||
using Google.Apis.Sheets.v4.Data;
|
||||
using WebAPI.Models;
|
||||
@@ -10,10 +11,15 @@ namespace WebAPI.Exports
|
||||
{
|
||||
private GoogleDriveHelper googleDriveHelper;
|
||||
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
||||
public googleSheetExport(GoogleDriveHelper _googleDriveHelper, SpreadsheetsResource.ValuesResource _googleSheetValues)
|
||||
private readonly IConfiguration configuration;
|
||||
public googleSheetExport(
|
||||
GoogleDriveHelper _googleDriveHelper,
|
||||
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
||||
IConfiguration _configuration)
|
||||
{
|
||||
googleDriveHelper = _googleDriveHelper;
|
||||
googleSheetValues = _googleSheetValues;
|
||||
configuration = _configuration;
|
||||
}
|
||||
public void export(Layer layer)
|
||||
{
|
||||
@@ -26,9 +32,9 @@ namespace WebAPI.Exports
|
||||
}
|
||||
|
||||
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
|
||||
body.Name = $"export-{DateTime.Now}";
|
||||
body.Name = $"{DateTime.Now.ToString(new CultureInfo("pl-PL"))}";
|
||||
body.MimeType = "application/vnd.google-apps.spreadsheet";
|
||||
body.Parents = new List<string> { "1c5GBQmsIoj6a9L-JYFTaLEZ3EfkbQHPt" };
|
||||
body.Parents = new List<string?> { configuration["exportDirectory"] };
|
||||
CreateRequest request = googleDriveHelper.Service.Files.Create(body);
|
||||
var file = request.Execute();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"GoogleClientId": "107631825312-bkfe438ehr9k9ecb2h76g802tj6advma.apps.googleusercontent.com",
|
||||
"Secret": "8393AF8EAEF8478CB738D44858690F9C7E2D19F65896DD9FBAA3EB2A6F493E80",
|
||||
"apiKey": "10763478CB738D4ecb2h76g803478CB738D4e",
|
||||
"exportDirectory": "1eTyCUzYbzVQB8f8sbNmvnebFXyW2-axt",
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"GoogleClientId": "#{google-backend-login-client-id}#",
|
||||
"Secret": "#{google-backend-login-secret}#",
|
||||
"apiKey": "#{api-key}#",
|
||||
"exportDirectory": "#{export-directory}#",
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
|
||||
Reference in New Issue
Block a user