Conservar el Prefijo de Comilla Simple del Valor de la Celda o del Rango

Escenarios de uso posibles

Cuando se agrega un valor dentro de la celda que tiene un apóstrofe inicial o una comilla simple, Microsoft Excel lo oculta, pero cuando se selecciona la celda, muestra el apóstrofe o comilla simple inicial en una barra de fórmulas como se muestra en la siguiente captura de pantalla.

todo:image_alt_text

Aspose.Cells for Python via .NET también oculta el apóstrofe inicial o la comilla simple como Microsoft Excel, pero establece Style.quote_prefix como verdadero para esa celda. Si establece un estilo vacío de la celda, entonces Style.quote_prefix vuelve a ser falso. Para lidiar con este problema, Aspose.Cells for Python via .NET proporciona la propiedad Style.quote_prefix, cuando se establece en falso, entonces Style.quote_prefix no se actualiza en absoluto y su antiguo valor se conserva. Esto significa que si el valor antiguo de la propiedad Style.quote_prefix era verdadero, seguirá siendo verdadero y si el valor antiguo era falso, seguirá siendo falso.

Preservar el prefijo de comilla simple del valor de la celda o rango

El siguiente código de muestra explica el uso de la propiedad Style.quote_prefix como se describió anteriormente. Por favor, lea los comentarios dentro del código y vea la salida en la consola del código que se muestra a continuación para obtener más ayuda.

Código de muestra

from aspose.cells import StyleFlag, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Create workbook
wb = Workbook()
# Access first worksheet
ws = wb.worksheets[0]
# Access cell A1
cell = ws.cells.get("A1")
# Put some text in cell, it does not have Single Quote at the beginning
cell.put_value("Text")
# Access style of cell A1
st = cell.get_style()
# Print the value of Style.quote_prefix of cell A1
print("Quote Prefix of Cell A1: " + str(st.quote_prefix))
# Put some text in cell, it has Single Quote at the beginning
cell.put_value("'Text")
# Access style of cell A1
st = cell.get_style()
# Print the value of Style.quote_prefix of cell A1
print("Quote Prefix of Cell A1: " + str(st.quote_prefix))
# Print information about StyleFlag.quote_prefix property
print()
print("When StyleFlag.quote_prefix is False, it means, do not update the value of Cell.Style.quote_prefix.")
print("Similarly, when StyleFlag.quote_prefix is True, it means, update the value of Cell.Style.quote_prefix.")
print()
# Create an empty style
st = wb.create_style()
# Create style flag - set StyleFlag.quote_prefix as false
# It means, we do not want to update the Style.quote_prefix property of cell A1's style.
flag = StyleFlag()
flag.quote_prefix = False
# Create a range consisting of single cell A1
rng = ws.cells.create_range("A1")
# Apply the style to the range
rng.apply_style(st, flag)
# Access the style of cell A1
st = cell.get_style()
# Print the value of Style.quote_prefix of cell A1
# It will print True, because we have not updated the Style.quote_prefix property of cell A1's style.
print("Quote Prefix of Cell A1: " + str(st.quote_prefix))
# Create an empty style
st = wb.create_style()
# Create style flag - set StyleFlag.quote_prefix as true
# It means, we want to update the Style.quote_prefix property of cell A1's style.
flag = StyleFlag()
flag.quote_prefix = True
# Apply the style to the range
rng.apply_style(st, flag)
# Access the style of cell A1
st = cell.get_style()
# Print the value of Style.quote_prefix of cell A1
# It will print False, because we have updated the Style.quote_prefix property of cell A1's style.
print("Quote Prefix of Cell A1: " + str(st.quote_prefix))

Salida de la consola

Quote Prefix of Cell A1: False

Quote Prefix of Cell A1: True

When StyleFlag.quote_prefix is False, it means, do not update the value of Cell.Style.quote_prefix.

Similarly, when StyleFlag.quote_prefix is True, it means, update the value of Cell.Style.quote_prefix.

Quote Prefix of Cell A1: True

Quote Prefix of Cell A1: False