none
how to insert single vertical line in merged cell using OPENXML Writer RRS feed

  • Question

  • Having following merged cell.

    1.C4-D4-E4-F4

    2.C5-D5-E5-F5

    3.C6-D6-E6-F6

    4.C7=D7-E7-F7

    Need to insert three single vertical line problematically using OPENXML

    Tuesday, October 16, 2012 6:57 PM

Answers

  • HI sudipta,

    Thanks for post in the MSDN Forum.

    Let’s see whether this snippet can help you:

                using (SpreadsheetDocument SSD = SpreadsheetDocument
                    .Open(Path, true))
                {
                    WorkbookPart WBP = SSD.WorkbookPart;
                    Workbook WB = WBP.Workbook;
                    Sheet SH = WB.Descendants<Sheet>()
                        .Where(SHT => SHT.Name == "Sheet1").FirstOrDefault();
                    WorksheetPart WSP = WBP.GetPartById(SH.Id) as WorksheetPart;
                    if (WSP != null)
                    {
                        Worksheet WS = WSP.Worksheet;
                        DataValidations DVS = null;
                        UInt32Value Count = null;
                        bool IsNull = true;
                        if (WS.Descendants<DataValidations>().Count() <= 0)
                        {
                            DVS = new DataValidations();
                            Count = (UInt32Value)0U;
                            PageMargins PMS = WS.Descendants<PageMargins>()
                                .FirstOrDefault();
                            PMS.Remove();
                            WS.Append(DVS);
                            WS.Append(PMS);
                        }
                        else
                        {
                            DVS = WS.Descendants<DataValidations>()
                                .FirstOrDefault();
                            Count = DVS.Count;
                            IsNull = false;
                        }
                        DataValidation DV = new DataValidation()
                        {
                            Type = DataValidationValues.List,
                            AllowBlank = true,
                            ShowInputMessage = true,
                            ShowErrorMessage = true,
                            SequenceOfReferences = new ListValue<StringValue>()
                            {
                                InnerText = "C4:F6"
                            }
                        };
                        Formula1 F1 = new Formula1();
                        F1.Text = "\"A,B,C\"";
                        DV.Append(F1);
    
                        DVS.Count = Count + 1;
                        DVS.Append(DV);
                        WS.Save();
                    }
                    else
                    {
                        SetLog("WSP is NULL", OXULogType.FATAL);
                    }
                }
            }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 17, 2012 7:44 AM
    Moderator