Especifique si la tabla dinámica es compatible con Excel 2003 mientras actualiza la tabla dinámica
Contents
[
Hide
]
Aspose.Cells proporciona elPivotTable.IsExcel2003Compatiblepropiedad que puede usar para especificar si la tabla dinámica es compatible con Excel2003 mientras actualiza la tabla dinámica. Si es verdadero, una cadena debe tener menos o igual a 255 caracteres, por lo que si la cadena tiene más de 255 caracteres, se truncará. Sifalso , una cadena no tendrá la restricción antes mencionada. El valor predeterminado esverdadero.
Especifique si la tabla dinámica es compatible con Excel 2003 mientras actualiza la tabla dinámica
El siguiente código de ejemplo explica el uso dePivotTable.IsExcel2003Compatible propiedad. La cadena original tiene 383 caracteres. Pero cuandoPivotTable.IsExcel2003Compatible se establece la propiedadverdadero y la tabla dinámica se actualiza, los datos de la celda B5 de la tabla dinámica se truncan y pasan a tener 255 caracteres. Sin embargo cuandoPivotTable.IsExcel2003Compatible se establece la propiedadfalso y la tabla dinámica se actualiza nuevamente, los datos de la celda B5 de la tabla dinámica no se truncan y siguen teniendo 383 caracteres. Lea los comentarios dentro del código para comprender mejor esta propiedad.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load source excel file containing sample pivot table | |
Workbook wb = new Workbook(dataDir + "sample-pivot-table.xlsx"); | |
// Access first worksheet that contains pivot table data | |
Worksheet dataSheet = wb.Worksheets[0]; | |
// Access cell A3 and sets its data | |
Cells cells = dataSheet.Cells; | |
Cell cell = cells["A3"]; | |
cell.PutValue("FooBar"); | |
// Access cell B3, sets its data. We set B3 a very long string which has more than 255 characters | |
string longStr = "Very long text 1. very long text 2. very long text 3. very long text 4. very long text 5. very long text 6. very long text 7. very long text 8. very long text 9. very long text 10. very long text 11. very long text 12. very long text 13. very long text 14. very long text 15. very long text 16. very long text 17. very long text 18. very long text 19. very long text 20. End of text."; | |
cell = cells["B3"]; | |
cell.PutValue(longStr); | |
// Print the length of cell B3 string | |
Console.WriteLine("Length of original data string: " + cell.StringValue.Length); | |
// Access cell C3 and sets its data | |
cell = cells["C3"]; | |
cell.PutValue("closed"); | |
// Access cell D3 and sets its data | |
cell = cells["D3"]; | |
cell.PutValue("2016/07/21"); | |
// Access the second worksheet that contains pivot table | |
Worksheet pivotSheet = wb.Worksheets[1]; | |
// Access the pivot table | |
PivotTable pivotTable = pivotSheet.PivotTables[0]; | |
// IsExcel2003Compatible property tells if PivotTable is compatible for Excel2003 while refreshing PivotTable. | |
// If it is true, a string must be less than or equal to 255 characters, so if the string is greater than 255 characters, | |
// it will be truncated. If false, a string will not have the aforementioned restriction. The default value is true. | |
pivotTable.IsExcel2003Compatible = true; | |
pivotTable.RefreshData(); | |
pivotTable.CalculateData(); | |
// Check the value of cell B5 of pivot sheet. | |
// It will be 255 because we have set IsExcel2003Compatible property to true. All the data after 255 characters has been truncated | |
Cell b5 = pivotSheet.Cells["B5"]; | |
Console.WriteLine("Length of cell B5 after setting IsExcel2003Compatible property to True: " + b5.StringValue.Length); | |
// Now set IsExcel2003Compatible property to false and again refresh | |
pivotTable.IsExcel2003Compatible = false; | |
pivotTable.RefreshData(); | |
pivotTable.CalculateData(); | |
// Now it will print 383 the original length of cell data. The data has not been truncated now. | |
b5 = pivotSheet.Cells["B5"]; | |
Console.WriteLine("Length of cell B5 after setting IsExcel2003Compatible property to False: " + b5.StringValue.Length); | |
// Set the row height and column width of cell B5 and also wrap its text | |
pivotSheet.Cells.SetRowHeight(b5.Row, 100); | |
pivotSheet.Cells.SetColumnWidth(b5.Column, 65); | |
Style st = b5.GetStyle(); | |
st.IsTextWrapped = true; | |
b5.SetStyle(st); | |
// Save workbook in xlsx format | |
wb.Save(dataDir + "SpecifyCompatibility_out_.xlsx", SaveFormat.Xlsx); |