【发布时间】:2019-04-13 01:09:05
【问题描述】:
我继承了一个大型 ASP .NET 项目,但我在编译它时遇到了问题,即使国际开发人员提供的代码运行良好(据称)。
我尝试将类名 ExcelWorksheet 更改为 ExcelWorksheet Dimension。我还尝试生成一个名为 ExcelWorksheet 的新类
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace OfficeOpenXml
{
/// <summary>
/// A class that can be used to represent the dimenension of a <see cref="OfficeOpenXmlExcelWorkSheet"/>
/// </summary>
class ExcelWorkSheetDimension
{
const string worksheetSchema = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
private string topLeft;
private string bottomRight;
private int firstRow;
private int firstCol;
private int lastRow;
private int lastCol;
private static String handleDimensionFromExcelWorksheet(ExcelWorkSheet w)
{
if (w == null)
throw new ArgumentNullException("w");
XmlNode n = w.WorksheetXml.DocumentElement.SelectSingleNode("//d:dimension", w.NameSpaceManager);
XmlAttribute dimensionRef = n.Attributes["ref"];
if ((dimensionRef != null) && (!String.IsNullOrEmpty(dimensionRef.Value)))
return dimensionRef.Value;
// no dimension available...?
throw new XmlException("dimension attribute not found!");
}
/// <summary>
/// Creates a ExcelWorkSheetDimension
/// </summary>
/// <param name="w">The <see cref="OfficeOpenXmlExcelWorkSheet"/> to create the dimension object for</param>
public ExcelWorkSheetDimension(ExcelWorkSheet w)
: this(handleDimensionFromExcelWorksheet(w))
{
}
/// <summary>
/// Creates a ExcelWorkSheetDimension using a string with Cell Range representation like 'A1:B5'.
/// </summary>
/// <param name="dimension">a string with Cell Range representation like 'A1:B5'</param>
public ExcelWorkSheetDimension(String dimension)
{
String[] dimensions = dimension.Split(':');
this.topLeft = dimensions[0];
this.bottomRight = dimensions[1];
if (!ExcelCell.IsValidCellAddress(topLeft) || (!ExcelCell.IsValidCellAddress(BottomRight)))
throw new ArgumentException("No valid excel sheet dimension!");
firstRow = ExcelCell.GetRowNumber(topLeft);
firstCol = ExcelCell.GetColumnNumber(topLeft);
lastCol = ExcelCell.GetColumnNumber(bottomRight);
lastRow = ExcelCell.GetRowNumber(bottomRight);
}
/// <summary>
/// Creates a ExcelWorkSheetDimension using a Excel two cell representations.
/// </summary>
/// <param name="topLeft">a top left cell, like 'A1'</param>
/// <param name="rightBottom">a right bottom cell, like 'B5'</param>
public ExcelWorkSheetDimension(String topLeft, String rightBottom)
:
this(String.Format("{0}:{1}", topLeft, rightBottom))
{
}
public string TopLeft { get { return topLeft; } }
public string BottomRight { get { return bottomRight; } }
public int FirstCol { get { return firstCol; } }
public int FirstRow { get { return firstRow; } }
public int LastCol { get { return lastCol; } }
public int LastRow { get { return lastRow; } }
}
}
输出:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5):警告 MSB3245:无法解析此引用。找不到程序集“ExcelPackage”。检查以确保该程序集存在于磁盘上。如果您的代码需要此引用,则可能会出现编译错误。
1>C:\Users\rgouldooz1\Desktop\RIC-BE\RICBackend\Controllers\UsersController.cs(60,23,60,30):警告 CS0108:'UsersController.GetUser()' 隐藏继承的成员 'ApiHelpers .BaseController.GetUser()'。如果要隐藏,请使用 new 关键字。
1>C:\Users\rgouldooz1\Desktop\RIC-BE\RICBackend\Helpers\ExcelWorkheetDimension.cs(24,65,24,79):错误 CS0246:找不到类型或命名空间名称“ExcelWorkSheet” (您是否缺少 using 指令或程序集引用?) 1>C:\Users\rgouldooz1\Desktop\RIC-BE\RICBackend\Helpers\ExcelWorkheetDimension.cs(42,40,42,54):错误 CS0246:找不到类型或命名空间名称“ExcelWorkSheet”(您是缺少 using 指令或程序集引用?)
========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
【问题讨论】:
-
ExcelWorkSheet这是你自己的课吗? -
不,这不是我制作的课程。我认为该错误与缺少包或程序集有关。
-
您可以点击代码上的
ExcelWorkSheet,然后按键盘上的Ctrl + .,看看它是否建议添加任何引用的命名空间。 -
是的,我已经做到了,它所建议的只是生成类“ExcelWorkSheet”。然而,这会产生更多错误。
标签: c#