diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index 6aa64ab..d3b05dc 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -153,7 +153,7 @@ differentialFormats = s.DifferentialFormats.Elements().ToDictionary(k => dfCount++); else differentialFormats = new Dictionary(); - + var sheets = dSpreadsheet.WorkbookPart.Workbook.Sheets; Int32 position = 0; foreach (Sheet dSheet in sheets.OfType()) @@ -304,7 +304,7 @@ } else xlTable.ShowAutoFilter = false; - + if (xlTable.ShowTotalsRow) { @@ -342,11 +342,11 @@ // **** MAYBE FUTURE SHAPE SIZE SUPPORT XDocument xdoc = GetCommentVmlFile(wsPart); - + foreach (Comment c in comments) { // find cell by reference var cell = ws.Cell(c.Reference); - + XLComment xlComment = cell.Comment as XLComment; xlComment.Author = authors[(int)c.AuthorId.Value].InnerText; //xlComment.ShapeId = (Int32)c.ShapeId.Value; @@ -360,9 +360,9 @@ LoadFont(runProperties, rt); } - + XElement shape = GetCommentShape(xdoc); - + LoadShapeProperties(xlComment, shape); var clientData = shape.Elements().First(e => e.Name.LocalName == "ClientData"); @@ -378,7 +378,7 @@ //var insetmode = (string)shape.Attributes().First(a=> a.Name.LocalName == "insetmode"); //xlComment.Style.Margins.Automatic = insetmode != null && insetmode.Equals("auto"); - + shape.Remove(); } } @@ -466,7 +466,7 @@ { return XLColor.FromHtml(color); } - + } private void LoadColorsAndLines(IXLDrawing drawing, XElement shape) @@ -489,7 +489,7 @@ { String opacityVal = opacity.Value; if (opacityVal.EndsWith("f")) - drawing.Style.ColorsAndLines.FillTransparency = + drawing.Style.ColorsAndLines.FillTransparency = Double.Parse(opacityVal.Substring(0, opacityVal.Length - 1), CultureInfo.InvariantCulture) / 65536.0; else drawing.Style.ColorsAndLines.FillTransparency = Double.Parse(opacityVal, CultureInfo.InvariantCulture); @@ -504,7 +504,7 @@ { String opacityVal = opacity.Value; if (opacityVal.EndsWith("f")) - drawing.Style.ColorsAndLines.LineTransparency = + drawing.Style.ColorsAndLines.LineTransparency = Double.Parse(opacityVal.Substring(0, opacityVal.Length - 1), CultureInfo.InvariantCulture) / 65536.0; else drawing.Style.ColorsAndLines.LineTransparency = Double.Parse(opacityVal, CultureInfo.InvariantCulture); @@ -522,7 +522,7 @@ else drawing.Style.ColorsAndLines.LineDash = XLDashStyle.SquareDot; } - else + else { switch (dashStyleVal) { @@ -711,7 +711,7 @@ return Double.Parse(value.Replace(knownUnit.Key, String.Empty), CultureInfo.InvariantCulture) * knownUnit.Value; } - + private void LoadDefinedNames(Workbook workbook) { @@ -911,7 +911,7 @@ if (!hasRuns) hasRuns = true; } - + if(!hasRuns) xlCell._cellValue = sharedString.Text.InnerText; @@ -974,7 +974,7 @@ else xlCell._dataType = XLCellValues.Number; } - + } } else if (cell.CellValue != null) @@ -1039,7 +1039,7 @@ LoadBorderValues(borderSource.RightBorder, border.SetRightBorder, border.SetRightBorderColor); LoadBorderValues(borderSource.TopBorder, border.SetTopBorder, border.SetTopBorderColor); LoadBorderValues(borderSource.BottomBorder, border.SetBottomBorder, border.SetBottomBorderColor); - + } private void LoadBorderValues(BorderPropertiesType source, Func setBorder, Func setColor ) @@ -1053,7 +1053,7 @@ } } - + private void LoadFill(Fill fillSource, IXLFill fill) { @@ -1111,7 +1111,7 @@ } var verticalTextAlignment = fontSource.Elements().FirstOrDefault(); - + if (verticalTextAlignment == null) return; fontBase.VerticalAlignment = verticalTextAlignment.Val != null ? verticalTextAlignment.Val.Value.ToClosedXml() : XLFontVerticalTextAlignmentValues.Baseline; @@ -1125,7 +1125,7 @@ { Int32 rowIndex = row.RowIndex == null ? ++lastRow : (Int32) row.RowIndex.Value; var xlRow = ws.Row(rowIndex, false); - + if (row.Height != null) xlRow.Height = row.Height; else @@ -1492,7 +1492,7 @@ conditionalFormat.ShowIconOnly = !iconSet.ShowValue.Value; if (iconSet.Reverse != null) conditionalFormat.ReverseIconOrder = iconSet.Reverse.Value; - + if (iconSet.IconSetValue != null) conditionalFormat.IconSetStyle = iconSet.IconSetValue.Value.ToClosedXml(); else @@ -1504,7 +1504,7 @@ { foreach (var formula in fr.Elements()) { - if (formula.Text != null + if (formula.Text != null && (conditionalFormat.ConditionalFormatType == XLConditionalFormatType.CellIs || conditionalFormat.ConditionalFormatType == XLConditionalFormatType.Expression)) { @@ -1515,7 +1515,7 @@ ws.ConditionalFormats.Add(conditionalFormat); } } - + } private static XLFormula GetFormula(String value) @@ -1523,7 +1523,7 @@ var formula = new XLFormula(); formula._value = value; formula.IsFormula = !(value[0] == '"' && value.EndsWith("\"")); - return formula; + return formula; } private void ExtractConditionalFormatValueObjects(XLConditionalFormat conditionalFormat, OpenXmlElement element) @@ -1731,6 +1731,7 @@ if (sheetView == null) return; + if (sheetView.RightToLeft != null) ws.RightToLeft = sheetView.RightToLeft.Value; if (sheetView.ShowFormulas != null) ws.ShowFormulas = sheetView.ShowFormulas.Value; if (sheetView.ShowGridLines != null) ws.ShowGridLines = sheetView.ShowGridLines.Value; if (sheetView.ShowOutlineSymbols != null) @@ -1983,10 +1984,10 @@ } } - + if (!UInt32HasValue(cellFormat.NumberFormatId)) return; - + var numberFormatId = cellFormat.NumberFormatId; string formatCode = String.Empty; @@ -2024,4 +2025,4 @@ return false; } } -} \ No newline at end of file +} diff --git a/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/Excel/XLWorkbook_Save.cs index c6084d6..998c2ef 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -159,8 +159,8 @@ } } - // Get the CalculationChainPart - //Note: An instance of this part type contains an ordered set of references to all cells in all worksheets in the + // Get the CalculationChainPart + //Note: An instance of this part type contains an ordered set of references to all cells in all worksheets in the //workbook whose value is calculated from any formula CalculationChainPart calChainPart; @@ -194,7 +194,7 @@ var workbookPart = document.WorkbookPart ?? document.AddWorkbookPart(); var worksheets = WorksheetsInternal; - + var partsToRemove = workbookPart.Parts.Where(s => worksheets.Deleted.Contains(s.RelationshipId)).ToList(); @@ -538,7 +538,7 @@ { workbook.WorkbookProtection = null; } - + if (workbook.BookViews == null) workbook.BookViews = new BookViews(); @@ -3420,6 +3420,10 @@ else sheetView.TabSelected = null; + if (xlWorksheet.RightToLeft) + sheetView.RightToLeft = true; + else + sheetView.RightToLeft = null; if (xlWorksheet.ShowFormulas) sheetView.ShowFormulas = true; @@ -4064,7 +4068,7 @@ } worksheetPart.Worksheet.InsertAfter(conditionalFormatting, previousElement); previousElement = conditionalFormatting; - cm.SetElement(XLWSContentManager.XLWSContents.ConditionalFormatting, conditionalFormatting); + cm.SetElement(XLWSContentManager.XLWSContents.ConditionalFormatting, conditionalFormatting); } } @@ -4636,4 +4640,4 @@ #endregion } -} \ No newline at end of file +} diff --git a/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML_Examples/ClosedXML_Examples.csproj index 5012f6d..6603cc8 100644 --- a/ClosedXML_Examples/ClosedXML_Examples.csproj +++ b/ClosedXML_Examples/ClosedXML_Examples.csproj @@ -73,6 +73,7 @@ + diff --git a/ClosedXML_Examples/Creating/CreateFiles.cs b/ClosedXML_Examples/Creating/CreateFiles.cs index 2b94f60..4a17302 100644 --- a/ClosedXML_Examples/Creating/CreateFiles.cs +++ b/ClosedXML_Examples/Creating/CreateFiles.cs @@ -67,6 +67,7 @@ new FreezePanes().Create(Path.Combine(path, "FreezePanes.xlsx")); new UsingTables().Create(Path.Combine(path, "UsingTables.xlsx")); new AddingRowToTables().Create(Path.Combine(path, "AddingRowToTables.xlsx")); + new RightToLeft().Create(Path.Combine(path, "RightToLeft.xlsx")); new ShowCase().Create(Path.Combine(path, "ShowCase.xlsx")); new CopyingWorksheets().Create(Path.Combine(path, "CopyingWorksheets.xlsx")); new InsertingTables().Create(Path.Combine(path, "InsertingTables.xlsx")); diff --git a/ClosedXML_Examples/Misc/RightToLeft.cs b/ClosedXML_Examples/Misc/RightToLeft.cs new file mode 100644 index 0000000..c9a5fa8 --- /dev/null +++ b/ClosedXML_Examples/Misc/RightToLeft.cs @@ -0,0 +1,21 @@ +using ClosedXML.Excel; +using System; + +namespace ClosedXML_Examples.Misc +{ + public class RightToLeft : IXLExample + { + public void Create(String filePath) + { + var wb = new XLWorkbook(); + + var ws = wb.Worksheets.Add("RightToLeftSheet"); + ws.Cell("A1").Value = "A1"; + ws.Cell("B1").Value = "B1"; + ws.Cell("C1").Value = "C1"; + ws.RightToLeft = true; + + wb.SaveAs(filePath); + } + } +} diff --git a/ClosedXML_Tests/ClosedXML_Tests.csproj b/ClosedXML_Tests/ClosedXML_Tests.csproj index d4d5ba6..5ea0151 100644 --- a/ClosedXML_Tests/ClosedXML_Tests.csproj +++ b/ClosedXML_Tests/ClosedXML_Tests.csproj @@ -248,6 +248,7 @@ + @@ -259,4 +260,4 @@ --> - \ No newline at end of file + diff --git a/ClosedXML_Tests/Examples/MiscTests.cs b/ClosedXML_Tests/Examples/MiscTests.cs index 38f7e8e..04a1ede 100644 --- a/ClosedXML_Tests/Examples/MiscTests.cs +++ b/ClosedXML_Tests/Examples/MiscTests.cs @@ -152,6 +152,12 @@ } [Test] + public void RightToLeft() + { + TestHelper.RunTestExample(@"Misc\RightToLeft.xlsx"); + } + + [Test] public void SheetProtection() { TestHelper.RunTestExample(@"Misc\SheetProtection.xlsx"); @@ -181,4 +187,4 @@ TestHelper.RunTestExample(@"Misc\WorkbookProperties.xlsx"); } } -} \ No newline at end of file +} diff --git a/ClosedXML_Tests/Resource/Examples/Misc/RightToLeft.xlsx b/ClosedXML_Tests/Resource/Examples/Misc/RightToLeft.xlsx new file mode 100644 index 0000000..1faf041 --- /dev/null +++ b/ClosedXML_Tests/Resource/Examples/Misc/RightToLeft.xlsx Binary files differ