Files
rmutr_report/Controllers/durable_articles_three.Controller.cs
kamonwan taengsuk 62b89761e4
All checks were successful
continuous-integration/drone/push Build is passing
Bug Fixed
2024-09-19 16:30:47 +07:00

116 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using FastReport;
using FastReport.Export.Csv;
using FastReport.Export.Mht;
using FastReport.Export.OoXML;
using FastReport.Export.Pdf;
using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml;
using rmutr_report.Models;
using Swashbuckle.AspNetCore.Annotations;
namespace rmutr_report.Controllers
{
[SwaggerTag("สำหรับรายงาน ง.3")]
public class DurableArticlesThree : Controller
{
readonly Setting _setting;
public DurableArticlesThree(Setting setting)
{
this._setting = setting;
}
[HttpPost, Route("reports/durable_articles_three/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetHrReport([FromRoute] string type,
[FromBody] durable_articles_three durable_articles_threes)
{
var _durable_articles_three = new List<durable_articles_three>() { durable_articles_threes };
Report report = new Report();
report.Load(_setting.report_path + "durable_articles_three.frx");
report.RegisterData(_durable_articles_three, "durable_articles_three");
report.Prepare();
MemoryStream stream = new MemoryStream();
switch (type)
{
case "view":
return File(stream, "application/pdf");
case "pdf":
PDFExport pdf = new PDFExport();
report.Export(pdf, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf");
break;
case "mht":
MHTExport mht = new MHTExport();
report.Export(mht, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "multipart/related");
break;
case "csv":
CSVExport csv = new CSVExport();
report.Export(csv, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "text/csv");
break;
case "doc":
case "docx":
Word2007Export word = new Word2007Export();
report.Export(word, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "appllication/vnd.ms-word");
break;
case "xls":
case "xlsx":
Excel2007Export excelExport = new Excel2007Export();
// {
// ShowProgress = true,
// PageBreaks = true
// };
// var textObject3 = report.FindObject("Text3") as FastReport.TextObject;
// var textObject7 = report.FindObject("Text7") as FastReport.TextObject;
// var textObject8 = report.FindObject("Text8") as FastReport.TextObject;
// if (textObject3 != null)
// {
// textObject3.WordWrap = true;
// }
// if (textObject7 != null)
// {
// textObject7.WordWrap = true;
// }
// if (textObject8 != null)
// {
// textObject8.WordWrap = true;
//}
report.Export(excelExport, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
// static double GetTextHeight(string text, double fontSize, bool wrapText)
// {
// if (string.IsNullOrEmpty(text))
// return 0;
//
//
// const double lineHeightFactor = 1.2;
//
// int lines = wrapText ? text.Split(new[] { '\n' }, StringSplitOptions.None).Length : 1;
// return lines * (fontSize * lineHeightFactor);
// }
return Ok();
}
}
}