private void TestPowerPointFile( List <PollerTestResult> retValue, String fileName, String type, Byte[] fileContent) { try { OfficeUtils.KillOfficeProcess("POWERPNT"); var tempFile = Path.Combine(Path.GetTempPath(), fileName); if (File.Exists(tempFile)) { File.Delete(tempFile); } File.WriteAllBytes(tempFile, fileContent); var conversionError = PowerPointConverter.ConvertToPdf(tempFile, tempFile + ".pdf"); if (!String.IsNullOrEmpty(conversionError)) { retValue.Add(new PollerTestResult(false, type + "Conversion with powerpoint converter failed:" + conversionError)); } else { retValue.Add(new PollerTestResult(true, type + "Conversion with powerpoint ok.")); } } catch (Exception ex) { retValue.Add(new PollerTestResult(false, type + "Conversion with powerpoint converter failed: " + ex.Message)); } }
public static byte[] LetoltesPDFFajl(IConfiguration config, Models.Dokumentum entityDokumentum) { var ext = entityDokumentum.Ext.ToLower(); var fb = LetoltesFajl(entityDokumentum, 0, entityDokumentum.Meret); if (ext == ".pdf") { return(fb.b); } else if (ext == ".xls" | ext == ".xlsx" | ext == ".doc" | ext == ".docx") { return(OfficeUtils.ToPdf(config, new OfficeParam { Bytes = fb.b, Ext = ext })); } else if (ext == ".jpg" | ext == ".jpeg" | ext == ".png") { using (var image = new MagickImage(fb.b)) { using (var ms = new MemoryStream()) { image.Write(ms, MagickFormat.Pdf); ms.Seek(0, SeekOrigin.Begin); var b = new byte[ms.Length]; ms.Read(b, 0, (int)ms.Length); return(b); } } } throw new Exception($"A(z) {ext} fájlok nem konvertálhatók!"); }
public FileContentResult OfficeExport(string keyword = null, string officeName = null, string state = null, string officeURL = null, string online = null, string officeNameArchive = null, string PCT = null, string WTO = null, string geographyType = null, string office = null, string officeValueCategory = null, string searchURL = null, string nationalNumberAssigned = null, string paris = null) { var query = OfficeUtils.BuildExportQuery(keyword ?? officeName, state, officeURL, online, officeNameArchive, PCT, WTO, geographyType, office, officeValueCategory, searchURL, nationalNumberAssigned, paris); var file = this._managementOfficeService.ExportByQuery(query); return(File(new UTF8Encoding().GetBytes(file.ToString()), "text/csv", $"Export-Office-{StringUtils.GetCurrentDateTimeAsString()}.csv")); }
public byte[] Print(IConfiguration config) { var op = new OfficeParam { Ext = ".docx" }; using (var msPdf = new MemoryStream()) { _outputDoc.Save(msPdf, SaveOptions.DocxDefault); op.Bytes = new byte[msPdf.Length]; msPdf.Read(op.Bytes, 0, (int)msPdf.Length); } return(OfficeUtils.ToPdf(config, op)); }
public ActionResult Office(int rowCount = 25, int page = 1, string keyword = null, string officeName = null, string state = null, string officeURL = null, string online = null, string officeNameArchive = null, string PCT = null, string WTO = null, string geographyType = null, string office = null, string officeValueCategory = null, string searchURL = null, string nationalNumberAssigned = null, string paris = null) { var searchResultObject = new VMSearchResultObject <Office> { Caption = "Office" }; var startIndex = (page - 1) * rowCount; var query = OfficeUtils.BuildQuery(startIndex, rowCount, keyword ?? officeName, state, officeURL, online, officeNameArchive, PCT, WTO, geographyType, office, officeValueCategory, searchURL, nationalNumberAssigned, paris); var offices = this._managementOfficeService.GetByQuery(query.Item1, query.Item2, out int total); searchResultObject.ObjectResult = new VMPageResult <Office> { StartIndex = startIndex, RowCount = rowCount, Page = page, Total = total, Records = offices }; if (!string.IsNullOrWhiteSpace(keyword)) { var searchResultWrapperList = this._searchService.Search(officeName ?? keyword); searchResultObject.SearchResult = new VMSearchResult { Table = searchResultWrapperList }; } ViewBag.Keyword = keyword ?? officeName; ViewBag.IsAdvanceSearch = string.IsNullOrWhiteSpace(keyword); return(View(searchResultObject)); }
public async Task <MemoryStream> ReportByDepartment(int fromYear, int toYear) { IXLWorkbook workbook = new XLWorkbook(); IXLWorksheet overviewSheet; var templatePath = Path.Combine(_environment.WebRootPath, "templates", "report-by-department-2021-03-08.xlsx"); using (var templatelWorkbook = new XLWorkbook(templatePath)) { if (templatelWorkbook.Worksheets.TryGetWorksheet("Sheet1", out overviewSheet)) { var departments = await _dataContext.Departments.OrderBy(x => x.Name).ToListAsync(); var listTrainingProgram_User = new List <List <TrainingProgram_User> >(); var listYear = new List <int>(); var firstRowOfDepartment = 3; var firstRowOfYear = 2; var firstColOfYear = 4; var lastRowOfDepartment = departments.Count + firstRowOfDepartment; for (var year = fromYear; year <= toYear; year++) { listYear.Add(year); listTrainingProgram_User.Add(await _dataContext.TrainingProgram_Users.Where(x => x.Year == year).Include(x => x.User).ToListAsync()); } // In năm xét for (var i = 0; i < listYear.Count; i++) { overviewSheet.Cell(firstRowOfYear, firstColOfYear + i).Value = listYear[i]; } // Merge cột năm xét overviewSheet.Range(overviewSheet.Cell(1, firstColOfYear), overviewSheet.Cell(1, firstColOfYear + listYear.Count - 1)).Merge(); for (var i = 0; i < departments.Count; i++) { //STT var STTCell = overviewSheet.Cell(firstRowOfDepartment + i, 1); STTCell.Value = i + 1; STTCell.Style.Alignment.SetVertical(XLAlignmentVerticalValues.Center); STTCell.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center); // Tên khoa phòng var departmentCell = overviewSheet.Cell(firstRowOfDepartment + i, 2); departmentCell.Value = departments[i].Name; departmentCell.Style.Font.SetBold(true); departmentCell.Style.Alignment.SetWrapText(true); // Số nhân viên trong khoa phòng var numOfUsers = _dataContext.Users.Where(x => x.DepartmentId == departments[i].Id).Count(); overviewSheet.Cell(firstRowOfDepartment + i, 3).Value = numOfUsers; // Số nhân viên đủ điều kiện for (var y = 0; y < listYear.Count; y++) { // Số người đủ điều kiện var eligibleUsers = listTrainingProgram_User[y] .Where(u => u.User.DepartmentId == departments[i].Id) .GroupBy(u => u.UserId) .Select(grp => new { Amount = grp.Sum(x => x.Amount) }) .Where(x => x.Amount >= 24) .Count(); overviewSheet.Cell(firstRowOfDepartment + i, firstColOfYear + y).Value = eligibleUsers; } } var totalUserCell = overviewSheet.Cell(lastRowOfDepartment + 1, 3); totalUserCell.FormulaA1 = OfficeUtils.Sum("C" + firstRowOfDepartment, "C" + lastRowOfDepartment); // Border var borderRange = OfficeUtils.GetRange(1, overviewSheet.ColumnsUsed().Count(), 1, overviewSheet.RowsUsed().Count()); overviewSheet.Range(borderRange).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; workbook.AddWorksheet(overviewSheet); } } MemoryStream memorystream = new MemoryStream(); workbook.SaveAs(memorystream); return(memorystream); }
public void InstallTest() { bool result = OfficeUtils.Install(@"C:\Program Files (x86)\ZHAOYIN\Cooperativeness.Office"); Assert.IsTrue(result); }
public void IsNeedAdmin() { bool result = OfficeUtils.IsNeedRunAsAdmin(); Assert.IsTrue(result); }