Added tables
This commit is contained in:
Родитель
ccdba5155a
Коммит
dace3f5c05
|
@ -7,7 +7,25 @@ namespace MicroStationTagExplorer.Core.Interop
|
|||
{
|
||||
internal class OpenXml
|
||||
{
|
||||
public static void ExportValues(string path, object[,] values, int nRows, int nColumns, string sheetName, string tableName)
|
||||
private static string ToRange(uint columnNumber)
|
||||
{
|
||||
uint end = columnNumber;
|
||||
string name = string.Empty;
|
||||
while (end > 0)
|
||||
{
|
||||
uint modulo = (end - 1) % 26;
|
||||
name = Convert.ToChar(65 + modulo).ToString() + name;
|
||||
end = (uint)((end - modulo) / 26);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
private static string ToRange(uint startRow, uint endRow, uint startColumn, uint endColumn)
|
||||
{
|
||||
return ToRange(startColumn) + startRow.ToString() + ":" + ToRange(endColumn) + endRow.ToString();
|
||||
}
|
||||
|
||||
public static void ExportValues(string path, object[,] values, uint nRows, uint nColumns, string sheetName, string tableName)
|
||||
{
|
||||
var spreadsheetDocument = SpreadsheetDocument.Create(path, SpreadsheetDocumentType.Workbook);
|
||||
|
||||
|
@ -29,14 +47,13 @@ namespace MicroStationTagExplorer.Core.Interop
|
|||
|
||||
var sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
|
||||
WriteValues(sheetData, values, nRows, nColumns);
|
||||
|
||||
|
||||
WriteTable(worksheetPart, 1U, values, nRows, nColumns);
|
||||
|
||||
workbookpart.Workbook.Save();
|
||||
spreadsheetDocument.Close();
|
||||
}
|
||||
|
||||
public static void WriteValues(SheetData sheetData, object[,] values, int nRows, int nColumns)
|
||||
public static void WriteValues(SheetData sheetData, object[,] values, uint nRows, uint nColumns)
|
||||
{
|
||||
for (int r = 0; r < nRows; r++)
|
||||
{
|
||||
|
@ -54,5 +71,55 @@ namespace MicroStationTagExplorer.Core.Interop
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteTable(WorksheetPart worksheetPart, uint tableID, object[,] values, uint nRows, uint nColumns)
|
||||
{
|
||||
string range = ToRange(1, nRows, 1, nColumns);
|
||||
|
||||
var autoFilter = new AutoFilter
|
||||
{
|
||||
Reference = range
|
||||
};
|
||||
|
||||
var tableColumns = new TableColumns()
|
||||
{
|
||||
Count = nColumns
|
||||
};
|
||||
|
||||
for (int c = 0; c < nColumns; c++)
|
||||
{
|
||||
var column = new TableColumn()
|
||||
{
|
||||
Id = (UInt32Value)(c + 1U),
|
||||
Name = values[0, c].ToString()
|
||||
};
|
||||
tableColumns.Append(column);
|
||||
}
|
||||
|
||||
var tableStyleInfo = new TableStyleInfo()
|
||||
{
|
||||
Name = "TableStyleMedium2",
|
||||
ShowFirstColumn = true,
|
||||
ShowLastColumn = false,
|
||||
ShowRowStripes = true,
|
||||
ShowColumnStripes = true
|
||||
};
|
||||
|
||||
var table = new Table()
|
||||
{
|
||||
Id = tableID,
|
||||
Name = $"Table{tableID}",
|
||||
DisplayName = $"Table{tableID}",
|
||||
Reference = range,
|
||||
TotalsRowShown = false
|
||||
};
|
||||
|
||||
table.Append(autoFilter);
|
||||
table.Append(tableColumns);
|
||||
table.Append(tableStyleInfo);
|
||||
|
||||
var tableDefinitionPart = worksheetPart.AddNewPart<TableDefinitionPart>($"rId{tableID}");
|
||||
tableDefinitionPart.Table = table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -534,7 +534,7 @@ namespace MicroStationTagExplorer.Core.ViewModels
|
|||
|
||||
public void ExportTagsFile(string fileName)
|
||||
{
|
||||
OpenXml.ExportValues(fileName, Project.TagValues, Project.Tags.Count + 1, 6, "Tags", "Tags");
|
||||
OpenXml.ExportValues(fileName, Project.TagValues, (uint)Project.Tags.Count + 1U, 6U, "Tags", "Tags");
|
||||
}
|
||||
|
||||
public void ExportTagsExcel()
|
||||
|
|
Загрузка…
Ссылка в новой задаче