Bevara Enkelkavot Prefix of Cell Value or Range

Möjliga användningsscenario

När du sätter ett värde i cellen som har ledande apostrof eller citattecken, döljer sedan Microsoft Excel det, men när du väljer cellen visas den ledande apostrof eller citattecken i en formlerad som visas i följande skärmbild.

todo:image_alt_text

Aspose.Cells för Python via .NET döljer också det inledande apostrofen eller enkla citattecknet som Microsoft Excel men ställer in Style.quote_prefix som true för den cellen. Om du ställer in en tom stil för cellen blir Style.quote_prefix igen false. För att hantera detta problem, tillhandahåller Aspose.Cells för Python via .NET egenskapen Style.quote_prefix, när den är inställd som false, då Style.quote_prefix uppdateras inte alls och dess gamla värde bevaras. Det betyder om det gamla värdet för Style.quote_prefix var true, kommer det förbli true och om det gamla värdet var false, kommer det förbli false.

Bevara enskild citattecken prefiks av cellvärde eller område

Följande exempelkod förklarar användningen av egenskapen Style.quote_prefix som tidigare beskrivits. Läs kommentarerna inne i koden och se konsolresultatet för koden nedan för mer hjälp.

Exempelkod

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))

Konsoloutput

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