Ticket T587713
Visible to All Users

could not convert variant of type null in to type (OleStr)

created 7 years ago

Hi team,
While fetching  TdxSpreadSheet  I am getting below error also attached screen shot .
could not convert variant of type null in to type (OleStr)
Below, what we are using code for the same.
 Var
siCell : Variant
Begin
ATableView := TdxSpreadSheet.ActiveSheetAsTable;
 siCell :=  ATableView.Cells[(123 - 1),0].AsVariant;
ATableView.CreateCell((123 - 1), 0).AsString := FieldByName('AcctNum');
siCell:= '' ;

end

Show previous comments (1)
MT MT
Manoj Tripathi 7 years ago

    Updated correct code :

    if not VarIsSoftNull(ATableView.Cells[(123- 1),0].AsVariant) then
         siCell :=  ATableView.Cells[(123 - 1),0].AsVariant;

    DevExpress Support Team 7 years ago

      Hello Manoj,

      It is difficult to answer why this happens without examining a sample project. I do not have the 'AcctNum' object on my side and it is unclear what the FieldByName method does. Would you please provide us with a small sample project so we can correctly replicate your scenario?

      As a side note, I do not think that it is reliable to use the ATableView.Cells array. Some cells may be nil in Spreadsheet documents. It is better to always use the ATableView.CreateCell method instead. If a certain cell is nil, it will be automatically created in this case.

      MT MT
      Manoj Tripathi 7 years ago

        Thanks Paulo,

        But I am getting error at this point .

        if not VarIsSoftNull(ATableView.Cells[(123- 1),0].AsVariant) then
        begin
        end ;

        How I can use ATableView.CreateCell method here ?

        Answers approved by DevExpress Support

        created 7 years ago (modified 7 years ago)

        Hi Paulo, it has been resolved now by using ATableView.CreateCell method .Thanks

          Show previous comments (1)
          MT MT
          Manoj Tripathi 7 years ago

            Thanks  Paulo,
            Below, I am using DisplayText property to get the values form the cells . but it’s giving error because cells contains currency symbols ($) format  .
            My question is – do we have any other property a part from DisplayText I can use here to get the actual  cell values
            Var
            ACell: TdxSpreadSheetCell;
            ATableView: TdxSpreadSheetTableView;
            cThisBeg1: currency ;
            Begin
            ACell := ActiveSheetAsTable.CreateCell((140, 0);
               if ACell.DisplayText <> '' then
               cThisBeg1 := StrToCURR(ACell.DisplayText) ;
             else
            cThisBeg1 := 0.00;
            End;

            DevExpress Support Team 7 years ago

              Hello Manoj,

              Please check if using the ACell.AsVariant, ACell.AsString, ACell.AsCurrency properties or other similar properties can help you accomplish your task. If they do not help, provide us with a small  sample project demonstrating the problematic behavior, so we can find an appropriate solution.

              MT MT
              Manoj Tripathi 7 years ago

                Thanks Paulo !!

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.