眾所周知,我們的世界在不斷發展,新技術幾乎每天都會出現。如今,不再需要在辦公室內建立整個基礎設施、雇用人員來監控設備、處理該設備出現的問題和其他困難。
如今,越來越多的服務提供業務云解決方案,例如FastReport Cloud。我們的服務使開發團隊免去不必要的工作;您不再需要考慮如何部署項目、在哪里租用或購買服務器最好、最有利可圖,以及使用什么技術進行部署。這一切我們都已經解決了,你只需利用它即可。
? ??FastReport .net下載(qun:585577353)https://www.evget.com/product/1861/download
如何使用FastReport云?
在本文中,我們將了解如何使用 SDK 在 FastReport Cloud 中創建報表并將其導出為任何方便的格式。
首先,我們創建一個項目并向其中添加 FastReport.Cloud.SDK.Web nuget 包。有了這個包,我們就可以方便地與 FastReport Cloud 進行通信,而無需 API。
我們還需要一個報告模板。此示例將使用我們演示中的 Box.frx:
創建項目并向其添加所有必要的依賴項后,您可以繼續分析示例。
首先,您需要在FastReport Cloud工作區中創建一個API密鑰;為此,請點擊鏈接https://fastreport.cloud。
單擊包含 API 密鑰的選項卡并創建一個新密鑰。如果該密鑰已存在,則可以通過右鍵單擊它并從下拉列表中選擇一個操作來復制它。
收到 API 密鑰后,我們返回到我們的應用程序。我們將密鑰寫入一個單獨的變量,如下例所示:
private const string ApiKey = "your API key";
接下來,我們需要創建將在程序中使用的主要對象:
var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("https://fastreport.cloud"); httpClient.DefaultRequestHeaders.Authorization = new FastReportCloudApiKeyHeader(ApiKey); var subscriptions = new SubscriptionsClient(httpClient); var rpClientTemplates = new TemplatesClient(httpClient); var rpClientExports = new ExportsClient(httpClient); var downloadClient = new DownloadClient(httpClient); var subscription = (await subscriptions.GetSubscriptionsAsync(0, 10)).Subscriptions.First(); var templateFolder = subscription.TemplatesFolder.FolderId; var exportFolder = subscription.ExportsFolder.FolderId;
之后,我們進入為云創建報告的階段。你可以這樣做:
TemplateCreateVM templateCreateVM = new TemplateCreateVM() { Name = "box.frx", Content = Convert.FromBase64String(TestData.BoxReport) //we send the frx file in byte format };
在上面的示例中,我們已經有一個字節格式的報告。如果您有 frx 格式的文件,則可以使用以下示例:
TemplateCreateVM templateCreateVM = new TemplateCreateVM() { Name = "box.frx", Content = File.ReadAllBytes("path to report") //we send the frx file in byte format to the path };
我們將 TemplateCreateVM 對象與報表一起上傳到 FastReport.Cloud 工作區:
TemplateVM uploadedFile = await rpClientTemplates.UploadFileAsync(templateFolder, templateCreateVM);
現在我們將報告導出為我們需要的格式。首先,您需要決定未來文件的格式和名稱。
ExportTemplateVM export = new ExportTemplateVM() { FileName = "box", Format = ExportFormat.Pdf //format to be exported };
我們導出為 PDF 格式:
ExportVM exportedFile = await rpClientTemplates.ExportAsync(uploadedFile.Id, export) as ExportVM; string fileId = exportedFile.Id; int attempts = 3; exportedFile = rpClientExports.GetFile(fileId); while (exportedFile.Status != FileStatus.Success && attempts >= 0) { await Task.Delay(1000); exportedFile = rpClientExports.GetFile(fileId); attempts--; }
我們通過報告完成了主要工作。我們收到了報告中的 pdf 文件:
如果您想手動下載文件,請轉到您的工作區并下載它,如下例所示:
您還可以使用以下示例通過 SDK 下載文件:
using (var file = await downloadClient.GetExportAsync(fileId)) { using (var pdf = File.Open("report.pdf", FileMode.Create)) { file.Stream.CopyTo(pdf); } }
現在您知道如何使用 SDK 在 FastReport Cloud 中創建、導出和下載文件。您可以通過以下鏈接找到本文中的示例:GitHub - FastReports/FastReport-Cloud。