Let $R$ be a commutative ring. Let $U\subseteq X:=\operatorname{Spec}(R)$ be an arbitrary open subset. Let $S$ be the multiplicative set of elements of $R$ which don't vanish anywhere on $U$. Explicitly, $U$ is open so by definition there exists some ideal $I\subseteq R$ such that $U$ is the prime ideals of $R$ which don't contain $I$, and then $S$ is the complement of the union of these prime ideals.
If $A:=\mathcal{O}_X(U)$ is the value of the structure sheaf at $U$, then restriction of functions gives us a map $R\to A$ and the image of every $s\in S$ is invertible in $A$ (because locally invertible) so we get a map $R[1/S]\to A$.
What is an example where this map is not an isomorphism of rings? I have no reason to believe that it is an isomorphism in general, but (a) if $U=D(f)$ (that is, $I=(f)$) then it is an isomorphism, and (b) if $X$ is affine 2-space over a field $k$ and $U$ is the complement of the origin -- the canonical "non-affine open in an affine" -- then $S$ is the non-zero constants and $R[1/S]=k[x,y]=A$. I need to expand my mental store of examples/counterexamples to answer this one, I think. Can someone help?