الحفاظ على بادئة الاقتباس الفردي لقيمة الخلية أو النطاق
سيناريوهات الاستخدام المحتملة
عندما تضع قيمة ما داخل الخلية التي تحتوي على رمز تأشيرة أو علامة اقتباس أحادية في البداية، يخفي Microsoft Excel ذلك، ولكن عند تحديد الخلية، يعرض الرمز التأشيري أو الاقتباس الأحادي في شريط الصيغة كما هو مبين في لقطة الشاشة التالية.
تخفي Aspose.Cells أيضًا بادئة الرصاصة الأو علامة اقتباس واحدة مثل Microsoft Excel ولكنها تضبط Style.QuotePrefix لتلك الخلية على صحيح. إذا قمت بتعيين نمط فارغ للخلية، فإن Style.QuotePrefix تصبح خاطئة مرة أخرى. من أجل التعامل مع هذه المشكلة، توفر Aspose.Cells خاصية StyleFlag.QuotePrefix، عندما يتم تعيينها خاطئة، فإن Style.QuotePrefix لا يتم تحديثها على الإطلاق ويتم الاحتفاظ بقيمتها القديمة. وهذا يعني إذا كانت القيمة القديمة للخاصية Style.QuotePrefix كانت صحيحة، فإنها ستظل صحيحة، وإذا كانت القيمة القديمة كانت خاطئة، فإنها ستظل خاطئة.
الحفاظ على بادئة اقتباس واحدة لقيمة الخلية أو النطاق
يشرح رمز العينة التالي استخدام الخاصية StyleFlag.QuotePrefix كما هو موضح سابقا. يرجى قراءة التعليقات داخل الكود ورؤية نتائج الكونسول للكود المعطى أدناه لمزيد من المساعدة.
الكود المثالي
// 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); |
مخرجات الوحدة
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