Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Find Arabic and other complex scripts in .xls sheets too (#345)
cre8ive-marketing44e205c26603
diff --git a/src/Filee.Engines/Infrastructure/ComplexScripts.cs b/src/Filee.Engines/Infrastructure/ComplexScripts.csindex 56d17b49..f49084fa 100644--- a/src/Filee.Engines/Infrastructure/ComplexScripts.cs+++ b/src/Filee.Engines/Infrastructure/ComplexScripts.cs@@ -12,6 +12,7 @@ using System.IO.Compression;using System.Text;using System.Text.RegularExpressions;using Filee.Engines.Hwp.Hwpx;+using Filee.Engines.Office.Sheets;namespace Filee.Engines.Infrastructure;@@ -161,6 +162,10 @@ internal static partial class ComplexScriptsif (IsZip(path))return FindInPackage(path, format);// Web archives and mail are MIME: their HTML (or text) part is what reaches the PDF.+ // Excel 97–2003 is binary: its cells, as the built-in reader reads them (issue #345).+ if (format is "xls" or "xlt")+ return XlsReader.Read(path).Sheets.SelectMany(sheet => sheet.Rows.Values).SelectMany(cells => cells.Values)+ .Select(cell => Find(cell.Text)).FirstOrDefault(script => script is not null);if (format is "mhtml" or "eml"){var message = MimeKit.MimeMessage.Load(path);diff --git a/tests/Filee.Engines.Tests/ArabicSheetTests.cs b/tests/Filee.Engines.Tests/ArabicSheetTests.csnew file mode 100644index 00000000..388a10ef--- /dev/null+++ b/tests/Filee.Engines.Tests/ArabicSheetTests.cs@@ -0,0 +1,60 @@+// Arabic in spreadsheets → PDF (issue #345). rhwp draws text one letter after the other, left to right, so a sheet+// with Arabic must go to LibreOffice for PDF, or be refused with that reason when LibreOffice isn't installed, for+// .xlsx and the older binary .xls alike.++using Filee.Core.Conversion;+using Filee.Core.Presets;+using Filee.Engines.Infrastructure;++namespace Filee.Engines.Tests;++public class ArabicSheetTests(EngineFixture fx) : IClassFixture<EngineFixture>+{+ private const string Statement = "كشف حساب";++ private string Xlsx(string name, string text)+ {+ var book = new XlsxBuilder();+ book.Sheet("Sheet1", XlsxBuilder.Row(1, book.Text("A1", text)));+ return book.Save(Path.Combine(fx.NewFolder(), name));+ }++ private string Xls(string name, string text)+ {+ var book = new XlsBuilder();+ book.Sheet("Sheet1").Text(0, 0, text);+ return book.Save(Path.Combine(fx.NewFolder(), name));+ }++ [Fact]+ public void Arabic_is_found_in_both_kinds_of_excel_file()+ {+ Assert.Equal("Arabic", ComplexScripts.FindInFile(Xlsx("statement.xlsx", Statement), "xlsx"));+ Assert.Equal("Arabic", ComplexScripts.FindInFile(Xls("statement.xls", Statement), "xls"));+ Assert.Null(ComplexScripts.FindInFile(Xls("plain.xls", "Account statement, 한국어"), "xls"));+ }++ [Theory]+ [InlineData("xlsx")]+ [InlineData("xls")]+ public async Task An_arabic_sheet_is_never_drawn_unshaped(string format)+ {+ var available = fx.Converters.Where(c => fx.Catalog.StatusOf(c).IsAvailable).Select(c => c.Id).ToHashSet();+ Assert.SkipUnless(available.Contains("rhwp") || available.Contains("libreoffice"), "neither rhwp nor LibreOffice is available");+ var path = format == "xlsx" ? Xlsx("statement.xlsx", Statement) : Xls("statement.xls", Statement);++ var job = await fx.ConvertAsync([path], new Preset { TargetFormat = "pdf" });++ var file = Assert.Single(job.Files);+ if (!available.Contains("libreoffice"))+ {+ Assert.Equal(FileState.Failed, file.State);+ Assert.Equal("error.needs_shaping", file.ErrorKey);+ Assert.Equal("Arabic", file.ErrorDetail);+ }+ else+ {+ Assert.Equal(FileState.Done, file.State); // through LibreOffice, which shapes it+ }+ }+}