123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- using System.Text.RegularExpressions;
- using System.Collections.Specialized;
- namespace Biff8Excel.Excel
- {
-
-
-
- public class ExcelSst : IDisposable
- {
- Records.SST m_sst;
- const int SSTMaxLen = 8224 - 8;
- const int ContinueMaxLen = 8224;
- int m_ContinueTimes;
-
- uint m_LabelCells;
- uint m_totalStrings;
- List<string> m_arrString;
- Hashtable m_htStringIndex;
- bool m_isContinue;
- uint[] m_ContinueIndex;
- uint[] m_ContinueStringLength;
- uint[] m_ContinueTotalStrings;
-
- uint m_SSTStringsLength;
- internal byte[] WriteRecord()
- {
- m_htStringIndex.Clear();
- m_sst.TotalStringCells = m_LabelCells;
- if (m_totalStrings > 0)
- {
- m_sst.SharedStrings = m_arrString;
-
- m_sst.TotalStringsLength = m_SSTStringsLength;
- if (m_isContinue)
- {
- m_sst.ContinueIndex = m_ContinueIndex;
- m_sst.ContinueStringLength = m_ContinueStringLength;
- m_sst.ContinueTotalStrings = m_ContinueTotalStrings;
- }
- }
-
- return m_sst.GetByte();
- }
-
-
-
-
-
-
- internal uint AddString(string st)
- {
- object tmp = m_htStringIndex[st];
- if (tmp != null)
- return Convert.ToUInt32(tmp);
- m_htStringIndex.Add(st, m_totalStrings);
- m_arrString.Add(st);
- m_totalStrings++;
- CalcStringLen(st);
- return m_totalStrings - 1;
- }
-
-
-
-
- private void CalcStringLen(string cs)
- {
- uint bytelen = (uint)Globals.GetDefaultBytesLength(cs);
- uint charcount = (uint)cs.Length;
- uint realLen = 0;
- if (bytelen != charcount)
- realLen = charcount * 2;
- else
- realLen = charcount;
-
- if (m_isContinue)
- {
- if (((m_ContinueTotalStrings[m_ContinueTimes - 1]+1) * 3 + m_ContinueStringLength[m_ContinueTimes - 1] + realLen) >= ContinueMaxLen)
- {
- AddContinue(realLen);
- return;
- }
- m_ContinueTotalStrings[m_ContinueTimes - 1]++;
- m_ContinueStringLength[m_ContinueTimes - 1] += realLen;
- return;
- }
- else
- {
- if ((m_totalStrings * 3 + m_SSTStringsLength + realLen) >= SSTMaxLen)
- {
- m_isContinue = true;
- AddContinue(realLen);
- return;
- }
- m_SSTStringsLength += realLen;
- return;
- }
- }
- private void AddContinue(uint realLen)
- {
- m_ContinueTimes++;
- Array.Resize<uint>(ref m_ContinueIndex, m_ContinueTimes);
- Array.Resize<uint>(ref m_ContinueStringLength, m_ContinueTimes);
- Array.Resize<uint>(ref m_ContinueTotalStrings, m_ContinueTimes);
- m_ContinueIndex[m_ContinueTimes - 1] = m_totalStrings - 1;
- m_ContinueStringLength[m_ContinueTimes - 1] += realLen;
- m_ContinueTotalStrings[m_ContinueTimes - 1] = 1;
- }
-
-
-
-
-
- public ExcelSst()
- {
- m_sst = new Biff8Excel.Records.SST();
- m_arrString = new List<string>();
- m_htStringIndex = new Hashtable();
-
-
-
-
- }
- #region IDisposable 成员
- public void Dispose()
- {
- m_sst = null;
- }
- #endregion
- }
- }
|