title: Rust Calamine Optional Parser Stops Reading Rows at First Empty Cell
body: <p>I've been following the examples in the calamine documentation for pulling values out of spreadsheets.</p>
  <p>They work fine but when trying to use parse empty cells the optional parser examples do not work.  I'm wondering if any of you can spot what I'm missing here.</p>
  <p>We have a spreadsheet with say 5 columns.</p>
  <p>Here's the code that is working:</p>
  <pre><code>fn example&lt;P: AsRef&lt;Path&gt;&gt;(xls_path: P) -&gt; Result&lt;(), Error&gt; {
      let mut workbook: Xlsx&lt;_&gt; = open_workbook(xls_path)?;
      let range = workbook
          .worksheet_range(&quot;Billing&quot;)
          .ok_or(Error::Msg(&quot;Cannot find 'Billing' sheet&quot;))??;
  
      let mut iter = RangeDeserializerBuilder::new().from_range(&amp;range)?.enumerate();
      
      while let Some((i, result)) = iter.next() {
          println!(&quot;{:?}&quot;, result);
          let (
              invoice_num,
              billing_date,
              client,
              amount,
              date_received,
              quarter,
              direct_expenses,
              expenses,
              net,
              total_expenses,
              gross_profit,
          ): (
              Option&lt;String&gt;,
              Option&lt;String&gt;,
              Option&lt;String&gt;,
              Option&lt;f64&gt;,
              Option&lt;String&gt;,
              Option&lt;String&gt;,
              Option&lt;f64&gt;,
              Option&lt;String&gt;,
              Option&lt;String&gt;,
              Option&lt;f64&gt;,
              Option&lt;f64&gt;,
          ) = result?;
  
          println!(&quot;Number {:?}&quot;, i);
          println!(&quot;Invoice #: {:?}&quot;, invoice_num);
          // print them all..
      }
  
      Ok(())
  }
  </code></pre>
  <p>Manually assigning them to Optional values causes every row to be printed regardless of what cells are empty inside of it.</p>
  <p>Now the example code takes this approach:</p>
  <pre><code>#[derive(Serialize, Deserialize, Debug, Clone)]
  struct RawExcelRow {
      #[serde(rename = &quot;INVOICE #&quot;, deserialize_with = &quot;de_opt_string&quot;)]
      invoice_num: Option&lt;String&gt;,
      #[serde(rename = &quot;BILLING DATE&quot;, deserialize_with = &quot;de_opt_string&quot;)]
      billing_date: Option&lt;String&gt;,
      #[serde(rename = &quot;CLIENT/PROJECT&quot;, deserialize_with = &quot;de_opt_string&quot;)]
      client_project: Option&lt;String&gt;,
      #[serde(rename = &quot;AMOUNT&quot;, deserialize_with = &quot;de_opt_f64&quot;)]
      amount: Option&lt;f64&gt;,
      #[serde(rename = &quot;DATE REC'D&quot;, deserialize_with = &quot;de_opt_string&quot;)]
      date_received: Option&lt;String&gt;,
  
  }
  
  fn example2() -&gt; Result&lt;(), Box&lt;dyn std::error::Error&gt;&gt; {
      if env::args().count() &gt; 2 {
          println!(&quot;{}&quot;, env::args().count());
          return Err(Box::new(Error::from(&quot;Enter the filename or leave blank for default&quot;)));
      }
  
      let path_string = format!(&quot;{}&quot;, env::current_dir().unwrap().display());
      let file_name = &amp;env::args().nth(1).ok_or(Error::Msg(&quot;Unkown filename&quot;))?;
      let xls_path = Path::new(&amp;path_string).join(file_name);
      
      let mut excel: Xlsx&lt;_&gt; = open_workbook(xls_path)?;
  
      let range = excel
        .worksheet_range(&quot;Billing&quot;)
        .ok_or(calamine::Error::Msg(&quot;Cannot find Billing sheet&quot;))??;
  
      let mut iter = RangeDeserializerBuilder::new().from_range::&lt;_, RawExcelRowDate&gt;(&amp;range)?.enumerate();
      while let Some((i, Ok(row))) = iter.next() {
          println!(&quot;Number {}&quot;, i);
          println!(&quot;Invoice #: {:?}&quot;, row.invoice_num);
          // print them all..
      }
      Ok(())
  }
  </code></pre>
  <p>And the deserializers:</p>
  <pre><code>fn de_opt_string&lt;'de, D&gt;(deserializer: D) -&gt; Result&lt;Option&lt;String&gt;, D::Error&gt; 
  where
      D: serde::Deserializer&lt;'de&gt;,
  {
      let data_type = calamine::DataType::deserialize(deserializer);
      match data_type {
          Ok(calamine::DataType::Error(e)) =&gt; Ok(None),
          Ok(calamine::DataType::Float(f)) =&gt; Ok(Some(f.to_string())),
          Ok(calamine::DataType::Int(i)) =&gt; Ok(Some(i.to_string())),
          Ok(calamine::DataType::String(s)) =&gt; Ok(Some(s)),
          Ok(calamine::DataType::DateTime(d)) =&gt; Ok(Some(d.to_string())),
          _ =&gt; Ok(None),  
      }
  }
  
  fn de_opt_f64&lt;'de, D&gt;(deserializer: D) -&gt; Result&lt;Option&lt;f64&gt;, D::Error&gt;
  where
      D: serde::Deserializer&lt;'de&gt;,
  {
      let data_type = calamine::DataType::deserialize(deserializer);
      match data_type {
          Ok(calamine::DataType::Error(_)) =&gt; Ok(None),
          Ok(calamine::DataType::Float(f)) =&gt; Ok(Some(f)),
          Ok(calamine::DataType::Int(i)) =&gt; Ok(Some(i as f64)),
          _ =&gt; Ok(None),
      }
  }
  </code></pre>
  <p>What happens is anytime I add a column to the struct <code>RawExcelRow</code> it stops at the first row  where one of columns corresponding to the struct has an empty cell.  The value I'm expecting to see is <code>None</code> but instead I see the error: <code>Deserializer error: missing field 'DATE REC'D'</code> as DATE REC'D is the first cell that is empty in one of the rows.  For example, row 18 has the first empty cell in the DATE REC'D column.  So only rows 1-17 will be parsed.</p>
  <p>I've looked through the source but I can't seem to find it's calling this error instead of just filling in a <code>None</code> value.  I've also tried using a deserializer based on visitors to no avail.</p>
  <p>P.S.</p>
  <p>calling <code>RangeDeserializerBuilder::with_headers(&amp;COLUMNS)</code> where <code>&amp;COLUMNS</code> is an array of column names, as they do in the example, instead of <code>::new()</code> makes no difference as <code>::new()</code> just uses the default value for <code>RangeDeserializer</code> which uses all of the headers.</p>