/*********************************************************************/
/* */
/* AgentService Framework */
/* www.agentservice.it */
/* */
/* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */
/* GNU Lesser General Public License */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation, */
/* version 2.1 of the License. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the */
/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/* */
/*********************************************************************/
// StringValueInCell.cs
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This file contains the implementation of the StringValueInCell
// class.
using System;
namespace lido.VSVisioEditor
{
/// This class demonstrates how to set a formula for the cell.
///
public class StringValueInCell
{
/// This method is the class constructor.
public StringValueInCell()
{
// No initialization is required.
}
/// This method sets the value of the specified Visio cell
/// to the new string passed as a parameter.
/// Cell in which the value is to be set
///
/// New string value that will be set
public void SetCellValueToString(
Microsoft.Office.Interop.Visio.Cell formulaCell,
string newValue)
{
try
{
// Set the value for the cell.
formulaCell.FormulaU = StringToFormulaForString(newValue);
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine(err.Message);
throw;
}
}
/// This method converts the input string to a Visio string by
/// replacing each double quotation mark (") with a pair of double
/// quotation marks ("") and then adding double quotation marks around
/// the entire string.
/// Input string that will be converted
/// to Visio String
/// Converted Visio string
public static string StringToFormulaForString(string inputValue)
{
string result = "";
string quote = "\"";
string quoteQuote = "\"\"";
try
{
result = inputValue != null ? inputValue : String.Empty;
// Replace all (") with ("").
result = result.Replace(quote, quoteQuote);
// Add ("") around the whole string.
result = quote + result + quote;
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine(err.Message);
throw;
}
return result;
}
}
}