0

I am try to make a barcode from a string, what is come from an excel cell. This cell contains special charakcters like"#&'!/()". When I try to make an image from the data, I get the next error:

Unhandled Exception System.InvalidOperationException: 'Invalid state.'

If i give the same string by hand like "string xy= "#&!"; ", the barcode will be created.

private void OpenFile()
    {
        Excel excel = new Excel("MyExcel.xlsx", 4);
        excel.WriteToCell(7,2,textBox1.Text);
        Char[] data= excel.readCell(2, 13).ToCharArray();
        excel.Save();
        excel.Close();
        Code128BarcodeDraw bdraw = BarcodeDrawFactory.Code128WithChecksum;
        string data2 = new string(data);
        pictureBox2.Image = bdraw.Draw(data2, 50,2);
    }
  • Debug and check if the data is being properly extracted from you excel file.That seems to be the only thing here that might be going wrong. – Samuel Middendorp Jan 22 '20 at 12:22

1 Answers1

0

Check to see if the text is properly sent to the function for it to be printed.