This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svn path=/trunk/old-code/; revision=156205
- Loading branch information
1 parent
fd3a432
commit 8352f77
Showing
12 changed files
with
986 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,74 @@ | |||
// | |||
// Cell.cs | |||
// | |||
// Authors: | |||
// Miguel de Icaza (miguel@novell.com) | |||
// | |||
// Copyright 2008 Novell, Inc (http://www.novell.com). | |||
// | |||
// Permission is hereby granted, free of charge, to any person obtaining | |||
// a copy of this software and associated documentation files (the | |||
// "Software"), to deal in the Software without restriction, including | |||
// without limitation the rights to use, copy, modify, merge, publish, | |||
// distribute, sublicense, and/or sell copies of the Software, and to | |||
// permit persons to whom the Software is furnished to do so, subject to | |||
// the following conditions: | |||
// | |||
// The above copyright notice and this permission notice shall be | |||
// included in all copies or substantial portions of the Software. | |||
// | |||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
// | |||
using System; | |||
|
|||
namespace Wahid { | |||
|
|||
public class Cell { | |||
public static Value DefaultValue = new StringValue (""); | |||
public Sheet Sheet { get; private set; } | |||
|
|||
public int Col { get; set; } | |||
public int Row { get; set; } | |||
|
|||
Value val; | |||
|
|||
/// <summary> | |||
/// Internal constructor, must only be called by Sheet.CreateCell | |||
/// </summary> | |||
public Cell (Sheet sheet, int col, int row) | |||
{ | |||
Sheet = sheet; | |||
Col = col; | |||
Row = row; | |||
val = DefaultValue; | |||
} | |||
|
|||
public Value Value { | |||
get { | |||
return val; | |||
} | |||
|
|||
set { | |||
val = value; | |||
} | |||
} | |||
|
|||
Formula formula; | |||
|
|||
public Formula Formula { | |||
get { | |||
return formula; | |||
} | |||
|
|||
set { | |||
formula = value; | |||
} | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
// | |||
// DirAccess.cs: primitive access to zip files, it must be unpacked. | |||
// | |||
// Authors: | |||
// Miguel de Icaza (miguel@novell.com) | |||
// | |||
// Copyright 2008 Novell, Inc (http://www.novell.com). | |||
// | |||
// Permission is hereby granted, free of charge, to any person obtaining | |||
// a copy of this software and associated documentation files (the | |||
// "Software"), to deal in the Software without restriction, including | |||
// without limitation the rights to use, copy, modify, merge, publish, | |||
// distribute, sublicense, and/or sell copies of the Software, and to | |||
// permit persons to whom the Software is furnished to do so, subject to | |||
// the following conditions: | |||
// | |||
// The above copyright notice and this permission notice shall be | |||
// included in all copies or substantial portions of the Software. | |||
// | |||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
// | |||
using System.IO; | |||
using System; | |||
|
|||
namespace Wahid { | |||
public class DirAccess : ZipAccess { | |||
string loc; | |||
|
|||
public DirAccess (string loc) | |||
{ | |||
this.loc = loc; | |||
} | |||
|
|||
public override Stream Get (string resource) | |||
{ | |||
return File.OpenRead (Path.Combine (loc, resource)); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,180 @@ | |||
// | |||
// Formula.cs | |||
// | |||
// Authors: | |||
// Miguel de Icaza (miguel@novell.com) | |||
// | |||
// Copyright 2008 Novell, Inc (http://www.novell.com). | |||
// | |||
// Permission is hereby granted, free of charge, to any person obtaining | |||
// a copy of this software and associated documentation files (the | |||
// "Software"), to deal in the Software without restriction, including | |||
// without limitation the rights to use, copy, modify, merge, publish, | |||
// distribute, sublicense, and/or sell copies of the Software, and to | |||
// permit persons to whom the Software is furnished to do so, subject to | |||
// the following conditions: | |||
// | |||
// The above copyright notice and this permission notice shall be | |||
// included in all copies or substantial portions of the Software. | |||
// | |||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
// | |||
using System; | |||
using System.Collections; | |||
using System.Text; | |||
|
|||
namespace Wahid { | |||
|
|||
public class Formula { | |||
|
|||
class Tokenizer { | |||
StringBuilder sb = new StringBuilder (); | |||
int len; | |||
int pos; | |||
string s; | |||
object putback; | |||
|
|||
public Tokenizer (string s) | |||
{ | |||
this.s = s.Trim (); | |||
len = s.Length; | |||
} | |||
|
|||
double GetFraction (StringBuilder sb) | |||
{ | |||
sb.Append (s[pos++]); | |||
if (pos < len && Char.IsDigit (s [pos])){ | |||
while (pos < len && Char.IsDigit (s [pos])) | |||
sb.Append (s [pos++]); | |||
} | |||
if (pos < len && s [pos] == 'e' || s [pos] == 'E'){ | |||
sb.Append (s [pos++]); | |||
if (pos < len && s [pos] == '+' || s [pos] == '-') | |||
sb.Append (s [pos++]); | |||
if (pos < len && Char.IsDigit (s [pos])) | |||
while (pos < len && Char.IsDigit (s [pos])) | |||
sb.Append (s [pos++]); | |||
} | |||
return double.Parse (sb.ToString ()); | |||
} | |||
|
|||
double GetNumber () | |||
{ | |||
sb.Length = 0; | |||
|
|||
while (pos < len && Char.IsDigit (s [pos])) | |||
sb.Append (s [pos++]); | |||
if (pos < len && s [pos] == '.') | |||
return GetFraction (sb); | |||
|
|||
return double.Parse (sb.ToString ()); | |||
} | |||
|
|||
ErrorValue TryError (string error, ErrorValue ret) | |||
{ | |||
if (error == null) | |||
throw new Exception ("Invalid error"); | |||
|
|||
string sub = s.Substring (pos); | |||
|
|||
if (s.StartsWith (error)){ | |||
pos += error.Length; | |||
return ret; | |||
} | |||
return null; | |||
} | |||
|
|||
object GetToken () | |||
{ | |||
if (putback != null){ | |||
object p = putback; | |||
putback = null; | |||
return p; | |||
} | |||
|
|||
while (pos < len){ | |||
char c = s [pos]; | |||
|
|||
if (c >= '0' && c <= '9') | |||
return GetNumber (); | |||
|
|||
if (c == '.'){ | |||
sb.Length = 0; | |||
return GetFraction (sb); | |||
} | |||
|
|||
if (c == '#'){ | |||
return TryError ("#DIV/0!", ErrorValue.DivisionByZero) ?? | |||
TryError ("#N/A!", ErrorValue.NA) ?? | |||
TryError ("#NAME?", ErrorValue.Name) ?? | |||
TryError ("#NULL?", ErrorValue.Null) ?? | |||
TryError ("#NUM!", ErrorValue.Num) ?? | |||
TryError ("#REF!", ErrorValue.Ref) ?? | |||
TryError (null, null); | |||
} | |||
if (c == '"'){ | |||
int start = ++pos; | |||
while (pos < len && s [pos] != '"') | |||
pos++; | |||
if (pos < len) | |||
return new StringValue (s.Substring (start, pos-start)); | |||
throw new Exception ("Unfinished quote"); | |||
} | |||
|
|||
if (c == ':' || c == ',' || c == ' ' || c == '^' || c == '*' || c == '/' || c == '+' || | |||
c == '-' || c == '&' || c == '=' || c == '%' || c == '[' || c == ']' || c == '!'){ | |||
pos++; | |||
return c; | |||
} | |||
|
|||
if (c == '>'){ | |||
if (pos + 1 < len && s [pos+1] == '='){ | |||
pos += 2; | |||
return ">="; | |||
} | |||
pos++; | |||
return '>'; | |||
} | |||
|
|||
if (c == '<'){ | |||
if (pos + 1 < len && s [pos+1] == '='){ | |||
pos += 2; | |||
return "<="; | |||
} | |||
|
|||
if (pos + 1 < len && s [pos+1] == '>'){ | |||
pos += 2; | |||
return "<>"; | |||
} | |||
pos++; | |||
return '<'; | |||
} | |||
|
|||
if (c == '[' || c == ']'){ | |||
return c; | |||
} | |||
|
|||
|
|||
} | |||
return null; | |||
} | |||
|
|||
void PutBack (object a) | |||
{ | |||
putback = a; | |||
} | |||
} | |||
|
|||
|
|||
public Formula (string s) | |||
{ | |||
// Parse the beast. | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
namespace Wahid { | |||
|
|||
static class Helper { | |||
|
|||
/// <summary> | |||
/// Allows C-like _("string") localization | |||
/// </summary> | |||
public static string _ (this object s) | |||
{ | |||
return s.ToString (); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
SOURCES = Cell.cs Formula.cs Locale.cs Sheet.cs Workbook.cs ZipAccess.cs Value.cs xlsx.cs | |||
|
|||
DESKTOP_SOURCES = DirAccess.cs | |||
|
|||
wahid.exe: main.cs $(SOURCES) $(DESKTOP_SOURCES) Makefile | |||
gmcs -debug -out:wahid.exe main.cs $(SOURCES) $(DESKTOP_SOURCES) -r:System.Xml.Linq -r:System.Core | |||
|
|||
run: wahid.exe | |||
mono --debug wahid.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
Wahid - A Spreadsheet engine | |||
---------------------------- | |||
|
|||
This is spreadsheet engine, initially without a GUI. | |||
|
|||
Ideally a number of user interfaces can be built on top of the | |||
spreadsheet engine: | |||
|
|||
* Silverlight (like Google's spreadsheets) | |||
|
|||
* gui.cs (the most powerful and awesome RIA in the world) | |||
|
|||
* command-line, to compute, and convert data. | |||
|
|||
* Gnome (worth doing?) | |||
|
|||
OOXML | |||
----- | |||
|
|||
Am drawing inspiration form the OOXML specification on how to | |||
structure the internals of this engine, but the idea is to | |||
have multiple importers and expoters. | |||
|
|||
Currently the code does not even unzip archives, it expects a | |||
directory called "test" to contain an unzipped OOXML file (I | |||
used the gnumeric test files for this). | |||
|
|||
The Zip support is split from the loader as in Silverlight we | |||
would want to use the Downloader class to unzip the files for | |||
us, while on the desktop we can use SharpZipLib. | |||
|
|||
Models and Views | |||
---------------- | |||
|
|||
The engine will communicate with the views through events that | |||
the views connect to. | |||
|
|||
In addition to the usual support for views for multiple | |||
spreadsheets, this will be useful to have views and | |||
controllers that can be connected on the backend to a server. | |||
This would allow multiple users to edit the spreadsheet | |||
simultaneously. | |||
|
|||
|
Oops, something went wrong.