<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Validate Range.Value2 on Excel in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10803507#M14427</link>
    <description>&lt;P&gt;Thank you very much for your help.&amp;nbsp; I don't understand your results, on your sheet you only have a pair of (0,0) and (30,30) coordinates and on your collection you have two and missing the others, but this could be a minor issue.&amp;nbsp; How you test for blank cells?&amp;nbsp; I think a key issue is the number format on Excel.&amp;nbsp; How you differentiate between a (0,0) coordinate (values) and a blank cell?&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 13:06:09 GMT</pubDate>
    <dc:creator>HJohn1</dc:creator>
    <dc:date>2021-12-06T13:06:09Z</dc:date>
    <item>
      <title>Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802133#M14423</link>
      <description>&lt;P&gt;I need to read coordinates (x,y) from excel workbooks, where x coordinates are stored on column B and y on column C on worksheets. I need to read these values for further process in AutoCAD. My problem is that I can't find a way to properly validate these values from Excel. Both columns in the worksheet are number formatted with two decimal places. Initially, I thought well this is not a big deal I will check, (Range.Value2 != Null &amp;amp;&amp;amp; Range.Value2 != string.Empty), to make sure the range is not blank. As you can see on the picture below the stored data contains 0.00 values and spaces. I only need to read the ranges (cells) which contain a valid values. I don't know how many rows contain values, so I need to go down on column B until all rows containing values have been read, say stop after reading 5 blank rows. My initial validation check generated errors like "Operator != cannot be applied to operands of type double and string" I also tried many combinations of checks and I have not been able to find one that I can use. Storing the range.value2 on a variable and checking after did not work because the number formatted cells return 0.0 which conflicts with the valid values.&amp;nbsp; I have always copied data from AutoCAD to Excel, this is the first time I need to copy from Excel to AutoCAD.&amp;nbsp; I hope some people here might have done this. Any suggestions will be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ExcelCoordinates.png" style="width: 346px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/997434i41F1D1D262D0E234/image-size/large?v=v2&amp;amp;px=999" role="button" title="ExcelCoordinates.png" alt="ExcelCoordinates.png" /&gt;&lt;/span&gt;Please if anyone can suggest a way to do this properly, I will be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 16:50:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802133#M14423</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2021-12-05T16:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802274#M14424</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you attach your code and excel file? So we work on it until we get best results&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 19:11:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802274#M14424</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2021-12-05T19:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802728#M14425</link>
      <description>&lt;LI-CODE lang="csharp"&gt;public Point2dCollection getCoordinates(Excel.Worksheet sheet)
{
Point2dCollection points = new Point2dCollection();
double X, Y;

Excel.Range rg = sheet.Range["B:B"];

for (int j = 1; j &amp;lt;= rg.Count; j++)
	{
	//I need to make sure cells in the worksheet are not empty/blank before I collect the coordinates.
	//Here I get errors when cells contain real coordinates.
	//Operator != cannot be applied to operands of type double and string.
	//Tried storing Value2 on a local variable but blank cells get 0.0.
	if (rg[j].Value2 != null &amp;amp;&amp;amp; rg[j].Value2 != string.Empty)
		{
			X = 0;
			Y = 0;
			//More code here.
			points.Add(new Point2d(X,Y));
		}
	}
return points;
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 03:30:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802728#M14425</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2021-12-06T03:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802899#M14426</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;It is better to attach the excel file&lt;BR /&gt;He worked with me on this case&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static Point2dCollection getCoordinates(Excel.Worksheet sheet)
{
Point2dCollection points = new Point2dCollection();
double X, Y;

Excel.Range rg = sheet.Range["B:B"];

for (int j = 1; j &amp;lt;= 6; j++)
{
//I need to make sure cells in the worksheet are not empty/blank before I collect the coordinates.
//Here I get errors when cells contain real coordinates.
//Operator != cannot be applied to operands of type double and string.
//Tried storing Value2 on a local variable but blank cells get 0.0.
if (rg[j].Value2 != null )
{
X = 0;
Y = 0;
//More code here.

points.Add(new Point2d(X, Y));
}
}
return points;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 415px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/997555iF5EFD5D7F3736F2C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.jpg" style="width: 654px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/997556iC5A5E09376674684/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.jpg" alt="Untitled.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 06:22:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10802899#M14426</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2021-12-06T06:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10803507#M14427</link>
      <description>&lt;P&gt;Thank you very much for your help.&amp;nbsp; I don't understand your results, on your sheet you only have a pair of (0,0) and (30,30) coordinates and on your collection you have two and missing the others, but this could be a minor issue.&amp;nbsp; How you test for blank cells?&amp;nbsp; I think a key issue is the number format on Excel.&amp;nbsp; How you differentiate between a (0,0) coordinate (values) and a blank cell?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 13:06:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10803507#M14427</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2021-12-06T13:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10803610#M14428</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Something like this ?&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;if (double.TryParse(sheet.Cells(i, j).value2.ToString(), out double x) &amp;amp;&amp;amp;
    double.TryParse(sheet.Cells(i, j + 1).value2.ToString(), out double y))
    points.Add(new Point2d(x, y);&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 13:44:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10803610#M14428</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-12-06T13:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10803618#M14429</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Results are just for testing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Because I only tested column b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Did you solve your problem? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if you don't solve it You must attach an excel file to work on it &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 13:47:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10803618#M14429</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2021-12-06T13:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10804201#M14430</link>
      <description>&lt;P&gt;_gile, thank you for your time.&amp;nbsp; I have already tried your suggestion.&amp;nbsp; I am caught in a catch 22, if I check for Null it fails when the cell is not blank (valid number) and if I don't check for Null it fails when it is&amp;nbsp; Null.&amp;nbsp; I am getting these errrors&lt;/P&gt;&lt;P&gt;1- "Cannot perform runtime binding on a null reference"&lt;/P&gt;&lt;P&gt;2- "Operator != cannot be applied to operands of type double and string"&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 17:26:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10804201#M14430</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2021-12-06T17:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10804334#M14431</link>
      <description>&lt;P&gt;I got this approach working.&amp;nbsp; I don't know if this is the correct way of going about it, but works.&amp;nbsp; If anyone has a better solution please, let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;for (int j = 1; j &amp;lt;= rg.Count; j++)
	{
	 object obj_X = range[i].Value2;

     object obj_Y = range[i].Offset[0, 1].Value2;

		if (obj_X != null &amp;amp;&amp;amp; obj_Y != null)
		{
			double.TryParse(obj_X.ToString(), out X);

			double.TryParse(obj_Y.ToString(), out Y);

			points.Add(new Point2d(X, Y));
		}
	}
	return points;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 18:19:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10804334#M14431</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2021-12-06T18:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Range.Value2 on Excel</title>
      <link>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10804433#M14432</link>
      <description>&lt;P&gt;I was trying something similar with a Console Application.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;double x = 0.0, y = 0.0;
var rgX = sheet.Range["B:B"];
var rgY = sheet.Range["C:C"];
for (int i = 1; i &amp;lt;= rgX.Count; i++)
{
    object objX = rgX[i].Value2;
    object objY = rgY[i].Value2;
    if (objX != null &amp;amp;&amp;amp; double.TryParse(objX.ToString(), out x) &amp;amp;&amp;amp;
        objY != null &amp;amp;&amp;amp; double.TryParse(objY.ToString(), out y))
    {
        Console.WriteLine("X: {0} Y: {1}", x, y);
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 19:05:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/validate-range-value2-on-excel/m-p/10804433#M14432</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-12-06T19:05:47Z</dc:date>
    </item>
  </channel>
</rss>

