电子表格灯是否具有在Right-to-Left Direction中创建 excel 工作表的任何功能。也就是说,excel表格的右侧应该出现一 列。
问问题
712 次
2 回答
1
SpreadSheetLight 确实保留了 RightToLeft 属性,如果您打开将 RightToLeft 属性设置为 True 的现有工作簿,您可以修改现有工作簿并保存或另存为,结果也将设置为 RightToLeft。
困难在于看似简单的事情的复杂性,因为它存在于 Excel 中的单个复选框中,该属性是按工作表视图设置的,尽管大多数都被忽略了该值。由于 SpreadSheetLight 确实坚持了这一点,这意味着它确实会读取它并将其保存回来,以便您可以实际更改它;但是,它没有暴露,因此您需要使用反射。
这是一个快速而肮脏的示例,说明如何在 VB.net 中为 Workbook/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
于 2017-06-28T12:26:48.740 回答
0
我已经对此进行了深入检查,并了解到SpreadsheetLight 目前不支持从右到左的工作表布局。
于 2017-06-10T17:23:46.150 回答