Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

本来文字列のセルで、一部が数値などの場合にも止まらないようにしました #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Assets/Terasurware/Editor/EntityTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@
using System.Collections;
using System.Collections.Generic;

public static class ICellExt {
    public static string ForceStringCellValue(this ICell cell)
    {
        string s = null;
        switch (cell.CellType)
        {
            case CellType.Blank:
                s = "";
                break;
            case CellType.Boolean:
                s = cell.BooleanCellValue + "";
                break;
            case CellType.Error:
                s = cell.ErrorCellValue + "";
                break;
            case CellType.Formula:
                s = cell.CellFormula;
                break;
            case CellType.Numeric:
                s = cell.NumericCellValue + "";
                break;
            case CellType.String:
                return cell.StringCellValue;
            case CellType.Unknown:
                s = "??? CellType.Unknown";
                break;
            default:
                Debug.LogError($"can't happen at sheet {cell.Sheet} row {cell.Row}");
                return "??? UNKNOWN " + cell.CellType;
        }
        Debug.LogWarning($"expected STRING cell, but {cell.CellType} is found at "
                        + $"sheet:{cell.Sheet.SheetName} row:{cell.Row.RowNum} column:{cell.ColumnIndex} s:[{s}]");
        // return s + " (warn: force converted)";
        return s;
    }
}

public class $ExcelData$ : ScriptableObject
{
public List<Sheet> sheets = new List<Sheet> ();
Expand Down
4 changes: 2 additions & 2 deletions Assets/Terasurware/Editor/ExcelImporterMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void ExportImporter()
builder.AppendFormat(tab + "cell = row.GetCell({1}); p.{0} = (float)(cell == null ? 0 : cell.NumericCellValue);", row.name, rowCount);
break;
case ValueType.STRING:
builder.AppendFormat(tab + "cell = row.GetCell({1}); p.{0} = (cell == null ? \"\" : cell.StringCellValue);", row.name, rowCount);
builder.AppendFormat(tab + "cell = row.GetCell({1}); p.{0} = (cell == null ? \"\" : cell.ForceStringCellValue());", row.name, rowCount);
break;
}
} else
Expand Down Expand Up @@ -351,7 +351,7 @@ void ExportImporter()
builder.AppendFormat(tab + "cell = row.GetCell({1}); p.{0}[{2}] = (float)(cell == null ? 0.0 : cell.NumericCellValue);", row.name, rowCount + i, i);
break;
case ValueType.STRING:
builder.AppendFormat(tab + "cell = row.GetCell({1}); p.{0}[{2}] = (cell == null ? \"\" : cell.StringCellValue);", row.name, rowCount + i, i);
builder.AppendFormat(tab + "cell = row.GetCell({1}); p.{0}[{2}] = (cell == null ? \"\" : cell.ForceStringCellValue());", row.name, rowCount + i, i);
break;
}
}
Expand Down