Javascript to generate excel 2

using System;
using CCC.Utility;

namespace CCC.BLL
{
	/// <summary>
	/// Summary description for JVExcelBuilder.
	/// </summary>
	public class JVExcelBuilder
	{
		private const int detailGridRowStart		= 11;
		private const int detailGridColumnStart		= 2; 

		private const int jvGridRowStart			= 21;
		private const int jvGridColumnStart			= 4;

		private int jvCombGridRowStart				= 31;
		private const int jvCombGridColumnStart		= 7;

		private Excel4JavaScript excel;
		private int detailGridCurrentRow;

		private int jvGridCurrentRow;
		private int jvCombGridCurrentRow;
		private int currentJVSheetIndex;

		public JVExcelBuilder(string strFileName, int originalSheetCount)
		{
			excel = new Excel4JavaScript(strFileName, originalSheetCount);
			detailGridCurrentRow = detailGridRowStart;
			jvGridCurrentRow = jvGridRowStart;
			jvCombGridCurrentRow = jvCombGridRowStart;
			currentJVSheetIndex = 2;
		}

		public string ToExcelString()
		{
			return excel.ToExcelString();
		}

		#region Detail sheet
		public void WriteDetailHeader1(string month, string rate)
		{
			string cellValue = string.Format("Accural rate of  Month ({0}) from RMB to USD : {1}", month, rate);
			excel.WriteComment( cellValue, 5, 2, 1);
		}

		public void WriteDetailHeader2(string month, string rate)
		{
			string cellValue = string.Format("Accural rate of  Month ({0}) from HKD to USD : {1}", month, rate);
			excel.WriteComment( cellValue, 6, 2, 1);
		}

		public void WriteDetailGridRow(params string[] strValues)
		{
			if( detailGridCurrentRow > detailGridRowStart )
				excel.InsertRow( detailGridCurrentRow+1, 1 );

			int currentColumn = detailGridColumnStart;
			foreach( string strValue in strValues )
			{
				excel.WriteComment( strValue.Replace("'", "\\'"), detailGridCurrentRow, currentColumn, 1);
				currentColumn++;
			}

			detailGridCurrentRow++;
		}

		public void DeleteLastDetailGridRow()
		{
			excel.DeleteRows(detailGridCurrentRow, 1);
		}
		#endregion

		#region JV Sheet
		public void SetFirstJVSheetName(string strWorkSheetName)
		{
			excel.SetWorkSheetName(2,strWorkSheetName);
		}
		public void CopyJVSheets(string sheetName)
		{
			excel.CopyWorkSheet(currentJVSheetIndex, sheetName);
			currentJVSheetIndex++;
		}

		public void WriteJVAccountDate(int sheetIndex, DateTime date)
		{
			excel.WriteComment(date.ToString("MM/dd/yyyy"),9, 11, sheetIndex+1);
		}

		public void WriteJVBatchName(int sheetIndex, string strValue)
		{
			excel.WriteComment(strValue, 10, 11, sheetIndex+1);
		}

		public void WriteJVJournalName(int sheetIndex, string strValue)
		{
			excel.WriteComment(strValue, 11, 11, sheetIndex+1);
		}

		public void WriteJVJournalDesc(int sheetIndex, string strValue)
		{
			excel.WriteComment(strValue, 12, 11, sheetIndex+1);
		}

		public void WriteJVJournalPeriod(int sheetIndex, string strValue)
		{
			excel.WriteComment(strValue, 14, 11, sheetIndex+1);
		}

		public void WriteJVGridRow(int sheetIndex, params string[] strValues)
		{
			if( jvGridCurrentRow > jvGridRowStart )
				excel.InsertRow( jvGridCurrentRow+1, sheetIndex+1 );

			int currentColumn = jvGridColumnStart;
			foreach( string strValue in strValues )
			{
				excel.WriteComment( strValue.Replace("'", "\\'"), jvGridCurrentRow, currentColumn, sheetIndex+1);
				currentColumn++;
			}

			jvGridCurrentRow++;
		}

		/// <summary>
		/// the index of JV sheets
		/// </summary>
		/// <param name="sheetIndex"></param>
		public void HideJVTemplateSheet(int sheetIndex)
		{
			excel.HideSheet(sheetIndex+1);
		}

		public void DeleteLastJVGridRow(int sheetIndex)
		{
			if( jvGridCurrentRow == jvGridRowStart )
			{
				excel.DeleteRows(jvGridCurrentRow+1, sheetIndex+1);
				jvCombGridRowStart += jvGridCurrentRow - jvGridRowStart - 1;
			}
			else
			{
				excel.DeleteRows(jvGridCurrentRow, sheetIndex+1);
				jvCombGridRowStart += jvGridCurrentRow - jvGridRowStart -2;
			}

			jvCombGridCurrentRow = jvCombGridRowStart;
		}

		public void WriteJVCombGridRow(int sheetIndex, params string[] strValues)
		{
			if( jvCombGridCurrentRow > jvCombGridRowStart + 1 )
				excel.InsertRow( jvCombGridCurrentRow+1, sheetIndex+1 );

			int currentColumn = jvCombGridColumnStart;
			foreach( string strValue in strValues )
			{
				excel.WriteComment( strValue.Replace("'", "\\'"), jvCombGridCurrentRow, currentColumn, sheetIndex+1);
				currentColumn++;
			}

			jvCombGridCurrentRow++;
		}

		public void DeleteLastJVCombGridRow(int sheetIndex)
		{
			if( jvCombGridCurrentRow - jvCombGridRowStart > 2 )
			{
				excel.DeleteRows(jvCombGridCurrentRow, sheetIndex+1);
			}

			jvGridCurrentRow = jvGridRowStart;
			jvCombGridRowStart = 31;
			jvCombGridCurrentRow = jvCombGridRowStart;
		}

		public void WriteJVTotalJournalVouchers(int sheetIndex, int count)
		{
			excel.WriteComment( "(Total: " + count.ToString() + " Journal vouchers)", jvCombGridRowStart+1, 9, sheetIndex+1);
		}

		public void WriteJVTruckerCode(int sheetIndex, string truckerCode)
		{
			excel.WriteComment( truckerCode, jvCombGridRowStart, 12, sheetIndex+1);
		}
		#endregion
	}
}

原文地址:https://www.cnblogs.com/zhangchenliang/p/1917495.html