最も迅速かつ簡単な解決策は、既に作成した製品を使用することです。
Excel Interop を使用して名前を付けて保存し、xlsb を xlsx に変換してから、通常どおり新しいファイルを読み取ります。通常、Excel Interop の使用は非常に遅いためお勧めしませんが、ファイルを変換するだけなら十分に高速です (通常の条件を想定)。
結果の xml ファイルを読み取るために、可能であれば Office Open XML SDK を使用することをお勧めします。
ここに私が以前に作ったものがあります:
public class XlConversion
{
public static void MarshalReleaseComObject(object comObject)
{
if ((comObject != null) && (Marshal.IsComObject(comObject)))
{
Marshal.ReleaseComObject(comObject);
}
}
public static void ConvertTsvToExcel(string inputFullPath, string outputExcelFullPath, bool deleteInput = false)
{
if (String.IsNullOrWhiteSpace(inputFullPath))
{
throw new ArgumentOutOfRangeException(nameof(inputFullPath));
}
if (String.IsNullOrWhiteSpace(outputExcelFullPath))
{
throw new ArgumentOutOfRangeException(nameof(outputExcelFullPath));
}
var inputFilename = new FileInfo(inputFullPath);
var xlFilename = new FileInfo(outputExcelFullPath);
const int maxSupportedXlFilenameLength = 218;
if (xlFilename.FullName.Length > maxSupportedXlFilenameLength)
{
throw new ArgumentOutOfRangeException(nameof(outputExcelFullPath), outputExcelFullPath, ("The full path filename (" + xlFilename.FullName.Length + " characters) is longer than Microsoft Excel supports (" + maxSupportedXlFilenameLength + " characters)"));
}
var excelApp = new Application();
Workbooks wbs = excelApp.Workbooks;
Workbook wb = wbs.Open(inputFilename.FullName);
wb.SaveAs(xlFilename.FullName, XlFileFormat.xlOpenXMLWorkbook);
try
{
wb.Close();
//excel.Quit();
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
MarshalReleaseComObject(wb);
MarshalReleaseComObject(wbs);
MarshalReleaseComObject(excelApp);
}
if (deleteInput)
{
File.Delete(inputFilename.FullName);
}
}
}