spreadsheetLight 是否具有在从右向左方向中创建Excel工作表的任何功能。也就是说, A 列应该出现在Excel工作表的右侧。
答案 0 :(得分:1)
SpreadSheetLight会保留RightToLeft属性,如果您打开一个RightToLeft属性设置为True的现有工作簿,您可以修改现有工作簿和Save或SaveAs,结果也将设置为RightToLeft。
难度是看似简单的事情的复杂性,因为它存在于Excel中的单个复选框中,属性是按照工作表视图设置的,但大多数都被忽略。由于SpreadSheetLight确实持续存在,这意味着它会读取它并将其保存回来,以便您可以实际更改它;但是,它没有暴露,所以你需要使用反射。
这是一个快速而又脏的示例,说明如何在VB.net中全局读取和修改工作簿/ SLDocument,应该很容易转换为C#
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports SpreadsheetLight
Public Module SlDocumentExtender
<Extension>
Public Sub SetRightToLeft(ByVal slDoc As SLDocument, ByVal rightToLeft As Boolean)
Dim sheetViews = GetSheetViews(slDoc.GetSlws)
If Not sheetViews.Any AndAlso rightToLeft Then 'Don't bother creating a default SheetView if false since it's the default
slDoc.FreezePanes(1, 0)
slDoc.UnfreezePanes()
sheetViews = GetSheetViews(slDoc.GetSlws)
End If
sheetViews.ForEach(Sub(sv) SetRightToLeftSheetView(sv, rightToLeft))
End Sub
<Extension>
Public Function GetRightToLeft(ByVal slDoc As SLDocument) As Boolean
Dim sheetViews = GetSheetViews(slDoc.GetSlws)
Return sheetViews.Any(Function(sv) GetRightToLeftSheetView(sv)) 'Empty collection will return false which is the default so we're good
End Function
<Extension>
Public Function GetSlws(ByVal slDoc As SLDocument) As Object 'SLWorksheet
Return slDoc.GetType.GetField("slws", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(slDoc)
End Function
Private Sub SetRightToLeftSheetView(ByVal sheetView As Object, ByVal rightToLeft As Boolean)
GetRequiredType(sheetView, "SpreadsheetLight.SLSheetView").GetProperty("RightToLeft", BindingFlags.Instance Or BindingFlags.NonPublic).SetValue(sheetView, rightToLeft)
End Sub
Private Function GetRightToLeftSheetView(ByVal sheetView As Object) As Boolean
Return GetRequiredType(sheetView, "SpreadsheetLight.SLSheetView").GetProperty("RightToLeft", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(sheetView)
End Function
Private Function GetSheetViews(ByVal slws As Object) As List(Of Object) 'List<SLSheetView>
Return DirectCast(GetRequiredType(slws, "SpreadsheetLight.SLWorksheet").GetProperty("SheetViews", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(slws), IList).OfType(Of Object).ToList()
End Function
Private Function GetRequiredType(ByVal obj As Object, ByVal requiredType_FullName As String) As Type
Dim type = obj.GetType
If Not type.FullName.Equals(requiredType_FullName) Then
Throw New NotSupportedException(String.Format("Type ""{0}"" is not supported, this method only handles only type ""{1}"".", type.FullName, requiredType_FullName))
End If
Return type
End Function
End Module
答案 1 :(得分:0)
我已经深入检查了这一点,并且知道SpreadsheetLight目前不支持从右到左的工作表布局。