Conserver le préfixe de guillemets simples de la valeur ou de la plage Cell

Scénarios d’utilisation possibles

Lorsque vous mettez une valeur dans la cellule qui comporte une apostrophe ou un guillemet simple, Microsoft Excel la masque, mais lorsque vous sélectionnez la cellule, elle affiche l’apostrophe ou le guillemet simple dans une barre de formule, comme indiqué dans la capture d’écran suivante.

tâche : image_autre_texte

Aspose.Cells masque également l’apostrophe principale ou le guillemet simple comme Microsoft Excel mais il définit leStyle.QuotePrefix commevrai pour cette cellule. Si vous définissez un style de cellule vide, alorsStyle.QuotePrefix devientfaux de nouveau. Afin de faire face à ce problème, le Aspose.Cells fournitStyleFlag.QuotePrefix propriété, lorsqu’elle est définiefaux , ensuiteStyle.QuotePrefixn’est pas du tout mis à jour et son ancienne valeur est conservée. Cela signifie que si l’ancienne valeur deStyle.QuotePrefixla propriété étaitvrai , il resteravrai et si l’ancienne valeur étaitfaux , il resterafaux.

Conserver le préfixe de guillemets simples de la valeur ou de la plage Cell

L’exemple de code suivant explique l’utilisation deStyleFlag.QuotePrefixpropriété telle que décrite précédemment. Veuillez lire les commentaires à l’intérieur du code et voir la sortie de la console du code ci-dessous pour plus d’aide.

Exemple de code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Create workbook
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Access cell A1
Cell cell = ws.Cells["A1"];
//Put some text in cell, it does not have Single Quote at the beginning
cell.PutValue("Text");
//Access style of cell A1
Style st = cell.GetStyle();
//Print the value of Style.QuotePrefix of cell A1
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix);
//Put some text in cell, it has Single Quote at the beginning
cell.PutValue("'Text");
//Access style of cell A1
st = cell.GetStyle();
//Print the value of Style.QuotePrefix of cell A1
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix);
//Print information about StyleFlag.QuotePrefix property
Console.WriteLine();
Console.WriteLine("When StyleFlag.QuotePrefix is False, it means, do not update the value of Cell.Style.QuotePrefix.");
Console.WriteLine("Similarly, when StyleFlag.QuotePrefix is True, it means, update the value of Cell.Style.QuotePrefix.");
Console.WriteLine();
//Create an empty style
st = wb.CreateStyle();
//Create style flag - set StyleFlag.QuotePrefix as false
//It means, we do not want to update the Style.QuotePrefix property of cell A1's style.
StyleFlag flag = new StyleFlag();
flag.QuotePrefix = false;
//Create a range consisting of single cell A1
Range rng = ws.Cells.CreateRange("A1");
//Apply the style to the range
rng.ApplyStyle(st, flag);
//Access the style of cell A1
st = cell.GetStyle();
//Print the value of Style.QuotePrefix of cell A1
//It will print True, because we have not updated the Style.QuotePrefix property of cell A1's style.
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix);
//Create an empty style
st = wb.CreateStyle();
//Create style flag - set StyleFlag.QuotePrefix as true
//It means, we want to update the Style.QuotePrefix property of cell A1's style.
flag = new StyleFlag();
flag.QuotePrefix = true;
//Apply the style to the range
rng.ApplyStyle(st, flag);
//Access the style of cell A1
st = cell.GetStyle();
//Print the value of Style.QuotePrefix of cell A1
//It will print False, because we have updated the Style.QuotePrefix property of cell A1's style.
Console.WriteLine("Quote Prefix of Cell A1: " + st.QuotePrefix);

Sortie console

Quote Prefix of Cell A1: False

Quote Prefix of Cell A1: True

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

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

Quote Prefix of Cell A1: True

Quote Prefix of Cell A1: False