这就是我在做的事情:
CellFormat cellFormat =
new CellFormat()
{ NumberFormatId = (UInt32Value)14U,
FontId = (UInt32Value)0U,
FillId = (UInt32Value)0U,
BorderId = (UInt32Value)0U,
FormatId = (UInt32Value)0U,
ApplyNumberFormat = true };
sd.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats.AppendChild<CellFormat>(cellFormat);
_dateStyleIndex = sd.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats.Count() - 1;
Run Code Online (Sandbox Code Playgroud)
然后在我的代码后面的某个地方
else if (type == DataTypes.DateTime)
{
DateTime dateTime = DateTime.Parse(text);
double oaValue = dateTime.ToOADate();
cell.CellValue = new CellValue(oaValue.ToString(CultureInfo.InvariantCulture));
cell.DataType = new EnumValue<CellValues>(CellValues.Date);
cell.StyleIndex = Convert.ToUInt32(_dateStyleIndex);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用Open XML SDK Tool验证生成的excel文件时,我收到以下验证错误:属性't'具有无效值'd'.枚举约束失败.
我在这里错过了什么?提前谢谢你的帮助.
PS:添加,这就是x:sheetData的样子.它给了我验证错误:
<x:sheetData xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:row r="2">
<x:c r="B2" t="s">
<x:v>0</x:v>
</x:c>
<x:c r="C2" t="s">
<x:v>1</x:v>
</x:c> …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 .xlsx 文件中格式化十进制和整数,如“1,000.00”。
生成样式表的代码:
private Stylesheet GenerateStylesheet()
{
//styling and formatting
var cellFormats = new CellFormats();
uint iExcelIndex = 164;
//number formats
var numericFormats = new NumberingFormats();
var nformat4Decimal = new NumberingFormat
{
NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
FormatCode = StringValue.FromString("#,##0.00")
};
numericFormats.Append(nformat4Decimal);
//cell formats
var cellFormat = new CellFormat
{
NumberFormatId = nformat4Decimal.NumberFormatId,
FontId = 0,
FillId = 0,
BorderId = 0,
FormatId = 0,
ApplyNumberFormat = BooleanValue.FromBoolean(true)
};
cellFormats.Append(cellFormat);
numericFormats.Count = UInt32Value.FromUInt32((uint)numericFormats.ChildElements.Count);
cellFormats.Count = UInt32Value.FromUInt32((uint)cellFormats.ChildElements.Count);
var stylesheet = new Stylesheet(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用openxml从工作表中删除所有公式。这是我正在尝试的:
internal static void ReplaceFormulaWithValue()
{
var res = _worksheetPart.Worksheet.GetFirstChild<SheetData>().Elements<Row>();
foreach (Row row in _worksheetPart.Worksheet.GetFirstChild<SheetData>().Elements<Row>())
{
foreach (Cell cell in row.Elements<Cell>())
{
if (cell.CellFormula != null &&
cell.CellValue != null)
{
string cellRef = cell.CellReference;
CalculationChainPart calculationChainPart = _spreadSheet.WorkbookPart.CalculationChainPart;
CalculationChain calculationChain = calculationChainPart.CalculationChain;
var calculationCells = calculationChain.Elements<CalculationCell>().ToList();
CalculationCell calculationCell = calculationCells.Where(c => c.CellReference == cellRef).FirstOrDefault();
//CalculationCell calculationCell = calculationChain.Elements<CalculationCell>().Where(c => c.CellReference == cell.CellReference).FirstOrDefault();
string value = cell.CellValue.InnerText;
UpdateCell(cell, DataTypes.String, value);
cell.CellFormula.Remove();
calculationCell.Remove();
}
}
}
SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
打开excel文档时,出现以下错误:
<?xml version="1.0" …Run Code Online (Sandbox Code Playgroud) 我有一个查询,我遍历一个表 - >为每个条目我迭代通过另一个表,然后计算一些结果.我使用游标迭代表.此查询需要很长时间才能完成.总是超过3分钟.如果我在C#中做类似的事情,其中表是数组或字典,它甚至不需要一秒钟.我做错了什么,如何提高效率?
DELETE FROM [QueryScores]
GO
INSERT INTO [QueryScores] (Id)
SELECT Id FROM [Documents]
DECLARE @Id NVARCHAR(50)
DECLARE myCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT [Id] FROM [QueryScores]
OPEN myCursor
FETCH NEXT FROM myCursor INTO @Id
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @Score FLOAT = 0.0
DECLARE @CounterMax INT = (SELECT COUNT(*) FROM [Query])
DECLARE @Counter INT = 0
PRINT 'Document: ' + CAST(@Id AS VARCHAR)
PRINT 'Score: ' + CAST(@Score AS VARCHAR)
WHILE @Counter < @CounterMax
BEGIN
DECLARE @StemId …Run Code Online (Sandbox Code Playgroud) 我有一个返回 Guid 列表的方法。我想要以下 linq 查询:
var results = (from t in CurrentDataSource.Table1
where t.Manager == userId && t.Profile != null
select t.Profile).ToList();
Run Code Online (Sandbox Code Playgroud)
为什么会出现以下错误:
Error 4 Cannot implicitly convert type 'System.Collections.Generic.List<System.Guid?>' to 'System.Collections.Generic.List<System.Guid>'
Run Code Online (Sandbox Code Playgroud)