a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.6 KiB

  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) Under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for Additional information regarding copyright ownership.
  5. The ASF licenses this file to You Under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed Under the License is distributed on an "AS Is" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations Under the License.
  14. ==================================================================== */
  15. using System;
  16. using NPOI.Util;
  17. namespace NPOI.HPSF
  18. {
  19. public class Vector
  20. {
  21. private readonly short _type;
  22. private TypedPropertyValue[] _values;
  23. public Vector(byte[] data, int startOffset, short type)
  24. {
  25. this._type = type;
  26. Read(data, startOffset);
  27. }
  28. public Vector(short type)
  29. {
  30. this._type = type;
  31. }
  32. public int Read(byte[] data, int startOffset)
  33. {
  34. int offset = startOffset;
  35. long longLength = LittleEndian.GetUInt(data, offset);
  36. offset += LittleEndian.INT_SIZE;
  37. if (longLength > int.MaxValue)
  38. throw new InvalidOperationException("Vector is too long -- "
  39. + longLength);
  40. int length = (int)longLength;
  41. _values = new TypedPropertyValue[length];
  42. if (_type == Variant.VT_VARIANT)
  43. {
  44. for (int i = 0; i < length; i++)
  45. {
  46. TypedPropertyValue value = new TypedPropertyValue();
  47. offset += value.Read(data, offset);
  48. _values[i] = value;
  49. }
  50. }
  51. else
  52. {
  53. for (int i = 0; i < length; i++)
  54. {
  55. TypedPropertyValue value = new TypedPropertyValue(_type, null);
  56. // be aware: not padded here
  57. offset += value.ReadValue(data, offset);
  58. _values[i] = value;
  59. }
  60. }
  61. return offset - startOffset;
  62. }
  63. public TypedPropertyValue[] Values
  64. {
  65. get { return _values; }
  66. }
  67. }
  68. }