JanKallman / EPPlus

Create advanced Excel spreadsheets using .NET
3.76k stars 1.18k forks source link

Some problems with Workbook.VbaProject.Modules with russian (cyrillic) locale Excel #372

Open Rayvor opened 5 years ago

Rayvor commented 5 years ago

Hi. I noticed that if you use Excel with different locale (example Russian), property Workbook.VbaProject.Modules starts throw InvalidOperationException("Vba module names can't contain unicode characters") in follow place:

ExcelVbaModule.cs

/// <summary>
/// The name of the module
/// </summary>
public string Name 
{   
    get
    {
        return _name;
    }
    set
    {
        if (value.Any(c => c > 255))
        {
            throw (new InvalidOperationException("Vba module names can't contain unicode characters"));
        }
        if (value != _name)
        {
            _name = value;
            streamName = value;
            if (_nameChangeCallback != null)
            {
                _nameChangeCallback(value);
            }
        }
    }
}

But if I remove condition if (value.Any(c => c > 255)) I get VbaProject.Modules names without errors.

The fact is that russian Excel create VBA project in new file with cyrillic names by default. Cyrillic names have unicode characters.

Rayvor commented 5 years ago

ReadDirStream() method in ExcelVbaProject.cs:488

case 0x19:
   currentModule = new ExcelVBAModule();
   currentModule.Name = GetUnicodeString(br, size);
   Modules.Add(currentModule);
break;

It get UnicodeString and trying set to currentModule.Name which throw excepltion