0

C# を使用して Excel のセルに書き込み中に、「この操作を完了するのに十分なストレージがありません」というエラーが表示されます。

Excelシートでは、セルごとに32,767文字を超える文字を書き込むことができないことを知っています. セルあたり 32,000 文字を書いています。最初の 3 つのセルを 1 列目に書き込むことができますが、4 列目には上記のエラーがスローされます。その理由は何ですか?何か案が?

xml_txt_length の合計の長さは 2,65,000 です。

エラーが発生している以下のコメントで、* ** * ***でコードをマークしました。 私のコードは以下です:

        if (xml_txt_length > 32000)  // checking length of text is more than 32,000. if yes than need to split it to write in cell
        {
            int counter = 0; // used to multiply to 32,000
            while (true)
            {
                if (counter == 0)
                {
                    cell_string = xmlText.Substring(0, 32000);
                    xml_string += cell_string;
                    // writing to cell for column1
                    oSheet3.Cells[counter + 1, 1] = cell_string;
                }

                else
                {
                    // if taken 32,000 characters exceeds the end length of string then go into this condition and take actual final position.  
                    if ((32000 * counter) + 32000 >= xml_txt_length) 
                    {
                        // below substring taking start position and up to end character of string instead of putting directly last 32,000th character position

                        cell_string = xmlText.Substring(32000 * counter, Convert.ToInt32(xml_txt_length - (32000 * counter)));

                        xml_string += cell_string;

                        //writing to cell for column 1
                        oSheet3.Cells[counter + 1, 1] = cell_string;
                        break;
                    }
                    else
                    {
                        // taking the start and upto 32,000 characters from string
                        cell_string = xmlText.Substring(32000 * counter, 32000);
                        xml_string += cell_string;

                        // writing to cell for column 1
                        // ********************************************************
                        // **** HERE I AM GETTING ERROR FOR CELL 4 IN COLUMN 1 ****

                        oSheet3.Cells[counter + 1, 1] = cell_string;
                        cell_string = string.Empty;
                    }
                }

                if (counter >= Math.Floor(xml_txt_length / 32000))
                    break;
                counter++;
            }
        }
        else
            oSheet3.Cells[1, 1] = xmlText;
4

0 に答える 0