⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 builtinfunction.cs

📁 Excel的操作,其中可以读取及写入Excel 文件
💻 CS
字号:
using System;
using System.Collections;

using Microsoft.Fawvw.Components.NExcel.ExcelCommon;
using Microsoft.Fawvw.Components.NExcel.Biff;

namespace Microsoft.Fawvw.Components.NExcel.Biff.Formula
{
	
	/// <summary> A built in function in a formula</summary>
	class BuiltInFunction:Operator, ParsedThing
	{
		/// <summary> Gets the token representation of this item in RPN
		/// 
		/// </summary>
		/// <returns> the bytes applicable to this formula
		/// </returns>
		override internal sbyte[] Bytes
		{
			get
			{
				// Get the data for the operands
				ParseItem[] operands = getOperands();
				sbyte[] data = new sbyte[0];
				
				for (int i = 0; i < operands.Length; i++)
				{
					sbyte[] opdata = operands[i].Bytes;
					
					// Grow the array
					sbyte[] cnewdata = new sbyte[data.Length + opdata.Length];
					Array.Copy(data, 0, cnewdata, 0, data.Length);
					Array.Copy(opdata, 0, cnewdata, data.Length, opdata.Length);
					data = cnewdata;
				}
				
				// Add on the operator byte
				sbyte[] newdata = new sbyte[data.Length + 3];
				Array.Copy(data, 0, newdata, 0, data.Length);
				newdata[data.Length] = !useAlternateCode()?Token.FUNCTION.Code:Token.FUNCTION.Code2;
				IntegerHelper.getTwoBytes(function.Code, newdata, data.Length + 1);
				
				return newdata;
			}
			
		}
		/// <summary> Gets the precedence for this operator.  Operator precedents run from 
		/// 1 to 5, one being the highest, 5 being the lowest
		/// 
		/// </summary>
		/// <returns> the operator precedence
		/// </returns>
		override internal int Precedence
		{
			get
			{
				return 3;
			}
			
		}
		/// <summary> The logger</summary>
		private static Logger logger;
		
		/// <summary> The function</summary>
		private Function function;
		
		/// <summary> The workbook settings</summary>
		private WorkbookSettings settings;
		
		/// <summary> Constructor</summary>
		/// <param name="ws">the workbook settings
		/// </param>
		public BuiltInFunction(WorkbookSettings ws)
		{
			settings = ws;
		}
		
		/// <summary> Constructor used when parsing a formula from a string
		/// 
		/// </summary>
		/// <param name="f">the function
		/// </param>
		/// <param name="ws">the workbook settings
		/// </param>
		public BuiltInFunction(Function f, WorkbookSettings ws)
		{
			function = f;
			settings = ws;
		}
		
		/// <summary> Reads the ptg data from the array starting at the specified position
		/// 
		/// </summary>
		/// <param name="data">the RPN array
		/// </param>
		/// <param name="pos">the current position in the array, excluding the ptg identifier
		/// </param>
		/// <returns> the number of bytes read
		/// </returns>
		public virtual int read(sbyte[] data, int pos)
		{
			int index = IntegerHelper.getInt(data[pos], data[pos + 1]);
			function = Function.getFunction(index);
			Assert.verify(function != Microsoft.Fawvw.Components.NExcel.Biff.Formula.Function.UNKNOWN, "function code " + index);
			return 2;
		}
		
		/// <summary> Gets the operands for this operator from the stack</summary>
		public override void getOperands(Stack s)
		{
		for (int i = 0; i < function.NumArgs; i++)
		{
		ParseItem pi = (ParseItem) s.Pop();
		add(pi);
		}
		}
		
		
		/// <summary> Gets the string for this functions
		/// 
		/// </summary>
		/// <param name="buf">the buffer to append
		/// </param>
		public override void  getString(System.Text.StringBuilder buf)
		{
			buf.Append(function.getName(settings));
			buf.Append('(');
			
			int numArgs = function.NumArgs;
			
			if (numArgs > 0)
			{
				ParseItem[] operands = getOperands();
				
				// operands are in the correct order 
				operands[numArgs - 1].getString(buf);
				
				for (int i = numArgs - 2; i >= 0; i--)
				{
					buf.Append(',');
					operands[i].getString(buf);
				}
			}
			
			buf.Append(')');
		}
		
		/// <summary> Adjusts all the relative cell references in this formula by the
		/// amount specified.  Used when copying formulas
		/// 
		/// </summary>
		/// <param name="colAdjust">the amount to add on to each relative cell reference
		/// </param>
		/// <param name="rowAdjust">the amount to add on to each relative row reference
		/// </param>
		public override void  adjustRelativeCellReferences(int colAdjust, int rowAdjust)
		{
			ParseItem[] operands = getOperands();
			
			for (int i = 0; i < operands.Length; i++)
			{
				operands[i].adjustRelativeCellReferences(colAdjust, rowAdjust);
			}
		}
		
		/// <summary> Called when a column is inserted on the specified sheet.  Tells
		/// the formula  parser to update all of its cell references beyond this
		/// column
		/// 
		/// </summary>
		/// <param name="sheetIndex">the sheet on which the column was inserted
		/// </param>
		/// <param name="col">the column number which was inserted
		/// </param>
		/// <param name="currentSheet">TRUE if this formula is on the sheet in which the
		/// column was inserted, FALSE otherwise
		/// </param>
		public override void  columnInserted(int sheetIndex, int col, bool currentSheet)
		{
			ParseItem[] operands = getOperands();
			for (int i = 0; i < operands.Length; i++)
			{
				operands[i].columnInserted(sheetIndex, col, currentSheet);
			}
		}
		
		/// <summary> Called when a column is inserted on the specified sheet.  Tells
		/// the formula  parser to update all of its cell references beyond this
		/// column
		/// 
		/// </summary>
		/// <param name="sheetIndex">the sheet on which the column was removed
		/// </param>
		/// <param name="col">the column number which was removed
		/// </param>
		/// <param name="currentSheet">TRUE if this formula is on the sheet in which the
		/// column was inserted, FALSE otherwise
		/// </param>
		internal override void  columnRemoved(int sheetIndex, int col, bool currentSheet)
		{
			ParseItem[] operands = getOperands();
			for (int i = 0; i < operands.Length; i++)
			{
				operands[i].columnRemoved(sheetIndex, col, currentSheet);
			}
		}
		
		
		/// <summary> Called when a column is inserted on the specified sheet.  Tells
		/// the formula  parser to update all of its cell references beyond this
		/// column
		/// 
		/// </summary>
		/// <param name="sheetIndex">the sheet on which the row was inserted
		/// </param>
		/// <param name="row">the row number which was inserted
		/// </param>
		/// <param name="currentSheet">TRUE if this formula is on the sheet in which the
		/// column was inserted, FALSE otherwise
		/// </param>
		internal override void  rowInserted(int sheetIndex, int row, bool currentSheet)
		{
			ParseItem[] operands = getOperands();
			for (int i = 0; i < operands.Length; i++)
			{
				operands[i].rowInserted(sheetIndex, row, currentSheet);
			}
		}
		
		/// <summary> Called when a column is inserted on the specified sheet.  Tells
		/// the formula  parser to update all of its cell references beyond this
		/// column
		/// 
		/// </summary>
		/// <param name="sheetIndex">the sheet on which the row was removed
		/// </param>
		/// <param name="row">the row number which was removed
		/// </param>
		/// <param name="currentSheet">TRUE if this formula is on the sheet in which the
		/// column was inserted, FALSE otherwise
		/// </param>
		internal override void  rowRemoved(int sheetIndex, int row, bool currentSheet)
		{
			ParseItem[] operands = getOperands();
			for (int i = 0; i < operands.Length; i++)
			{
				operands[i].rowRemoved(sheetIndex, row, currentSheet);
			}
		}
		static BuiltInFunction()
		{
			logger = Logger.getLogger(typeof(BuiltInFunction));
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -